CSS cross-browser implementation Float:center_ experience Exchange

Source: Internet
Author: User
Copy the Code code as follows:


  • List One

  • List II

  • List three




We want the implementation of Li to be floating, and centered (the number of Li is not fixed, the UL width is unknown). can set the UL Text-align:center, and then set the display of Li, you can achieve the center, but this is not our original intention, we need to implement Float:center.

Here we have to revisit the position:relative, which offsets the position in the normal document flow based on attributes such as Left,right,top,bottom. Then we can let UL for position:relative;left:50%, and then let Li like left float, in Let it position:relative;right:50% (or left:-50%), then Li is like floating in the middle of the center. Don't say much nonsense, try it first.
Copy the Code code as follows:
#macji {
position:relative;
width:100%;
height:80px;
Background-color: #eee;
Text-align:center;
Overflow:hidden;
}
#macji. macji-skin{
Float:left;
position:relative;
left:50%;
}
#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.