html+css-Horizontal Center-Indefinite block element Method (ii)

Source: Internet
Author: User

Source: http://www.imooc.com/code/6364

In addition to inserting the table label in the previous section, you can center the indeterminate block horizontally, this section describes the 2 ways to achieve this effect, changing the display type of the element to be the inline element, and using its properties to set directly.

The second method: Change the display of the block-level element to the inline type (set to the inline element display), then use text-align:center to achieve the centering effect. Here's an example:

HTML code:

<Body><Divclass= "Container">    <ul>        <Li><ahref="#">1</a></Li>        <Li><ahref="#">2</a></Li>        <Li><ahref="#">3</a></Li>    </ul></Div></Body>

CSS code:

<style>. Container{text-align:Center;}/*margin:0;padding:0 (eliminates the gap between text and div borders)*/. Container ul{List-style:None;margin:0;padding:0;Display:inline;}/*margin-right:8px (Sets the interval between Li text)*/. Container Li{Margin-right:8px;Display:inline;}</style>

This approach has the advantage of not adding no semantic tags to the first method, but there are some problems: it changes the display type of the block element to inline, so it has fewer functions, such as setting the length value.

html+css-Horizontal Center-Indefinite block element Method (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.