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)