What is important about ul center is that padding = 0

Source: Internet
Author: User

Recently, I encountered a problem when I was working on a website: the navigation bar I built with UL and Li tags wanted to be centered without being sure about the number of Li and the width of Li and ul, however, after using text-align: Center for UL, it does not have the expected effect. The original page structure is: <Div id = "menu"> <ul class = "menu_ul"> <li class = "menu_li"> <a href = "#"> firede </a> </Li> <li class = "menu_li"> <a href = "#"> style5 </a> </LI> </ul> </div> the style table structure is: <style> # menu {...}. menu_ul {...}. menu_li {...} </style> there is no problem in this way, but to implement a function, we define an ID (menu) and two classes (menu_ul, menu_li ), in this way, the CSS file is bloated. The reason why I cannot solve the UL center problem is that CSS is too messy to write, and I am confused by the last link, the code of the definition structure is mixed in various code written to display the effect, so it is messy. When the brain is dizzy, I don't want to modify it, So I re-wrote the code to implement the above functions. The page structure:

<Div id = "menu"> <ul>

<Li> <a href = "#"> firede </a> </LI>

<Li> <a href = "#"> style5 </a> </LI>

</Ul> </div> complete style sheet: <style>

# Menu {text-align: center ;}

# Menu ul {padding: 0; margin: 0 ;}

# Menu Li {display: inline; padding: 0 10px ;}

</Style> in this way, UL cannot be centered. Check my code. It turns out that I added a float: left in the Li style, because the display defined is not a block, but an inline, so it cannot be floating, as a result, UL cannot be centered. To sum up, when writing a webpage structure, it is best to use a relatively uniform CSS name for the same function module. If you can define a style name to solve the problem, try not to define multiple names, and try to make the code as concise as possible. Because the code is bloated, it is easy to have problems, and it is difficult to find out where the error is. Use a series of styles such as menu, menu ul, menu Li, menu A, and menu A: hover instead of defining menus such as menu_ul and menu_ul_li, but the name is actually messy. Habits are the essence of past experiences in the subconscious, but with the advancement of technology, many past habits have become obstacles to further improvement. At this time, we need to refer to more standards, check whether the past habits are worth sticking. The same is true for websites. standards can improve efficiency, improve performance, and specify the direction. Standardized Web design will help us increase the efficiency of website maintenance.

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.