Ul Li center in CSS

Source: Internet
Author: User

I always thought that the center alignment of UL Li has been mastered. However, during the recent project, it was found that the float: Left method of Li had a problem, that is, it could not be centered (horizontally ), you can only use the padding-left or margin-right method to fix the center. However, the display on the wide screen may be different from that on the narrow screen.

 

This method is mainly implemented by using the floating fixed width of Li. By default, the display of Li is a block. changing this attribute to inline can solve the UL Li center problem.

<Style type = "text/CSS">
# Bnav {
Margin-top: 10px;
Background: # d9ebf5;
Text-align: center;
}
# Bnav ul {
Padding: 4px 0;
Margin: 0;
Overflow: hidden;
}
# Bnav ul Li {
Display: inline;
Padding: 0;
}
</Style>

<Div id = "bnav" class = "bnav">
<Ul>
<Li> <a href = "index. aspx" Title = "home"> Home </a> </LI>
<Li> | </LI>
<Li> <a href = "info. aspx? Info_id = 8 "Title =" About Us "> about us </a> </LI>
<Li> | </LI>
<Li> <a href = "info. aspx? Info_id = 9 "Title =" department Design "> department Design </a> </LI>
<Li> | </LI>
<Li> <a href = "info. aspx? Info_id = 10 "Title =" law declaration "> law declaration </a> </LI>
<Li> | </LI>
<Li> <a href = "info. aspx? Info_id = 11 "Title =" Contact Us "> Contact Us </a> </LI>
<Li> | </LI>
<Li> <a href = "info. aspx? Info_id = 12 "Title =" Application Agent "> Application Agent </a> </LI>
<Li> | </LI>
<Li> <a href = "info. aspx? Info_id = 13 "Title =" Job Services "> job services </a> </LI>
<Li> | </LI>
<Li> <a href = "info. aspx? Info_id = 14 "Title =" Apply link "> apply link </a> </LI>
</Ul>
</Div>
 

Display Effect: Click here to preview

Note that UL should be added with margin: 0; padding: 0; to ensure compatibility with various browsers.

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.