Cross-browser CSS float: Center

Source: Internet
Author: User

CopyCode The Code is as follows: <Div id = "macji">
<Ul class = "macji-skin">
<Li> List 1 </LI>
<Li> List 2 </LI>
<Li> List 3 </LI>
</Ul>
</Div>

We hope that the Li is floating and centered (the number of Li is not fixed, and the UL width is unknown ). You can set UL's text-align: center, and then set Li's display to center, but this is not our original intention. We need to implement float: Center.

here, we need to review position: relative, which is offset in normal document streams based on left, right, top, bottom, and other attributes. Then we can set ul to position: relative; left: 50%, and then let the Li image float left and let it position: relative; Right: 50% (or left:-50% ), then Li is centered like floating in the middle. Try it first. copy Code the code is as follows: # macji {
position: relative;
width: 100%;
Height: 80px;
background-color: # Eee;
text-align: center;
overflow: hidden;
}< br> # macji. macji-skin {
float: Left;
position: relative;
left: 50%;
}< BR ># macji. macji-skin Li {
position: relative;
right: 50%;
float: Left;
margin: 10px;
padding: 0 10px;
border: solid 1px #000;
line-Height: 60px;
}

Related Article

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.