简体   繁体   中英

How to center list tags inside an unordered list?

How can list tags that are given a display:block and are floated left, be centered inside an unordered list.

The HTML:

        <div id="navigation">
            <ul>
                <li>Home</li>
                <li>About Us</li>
                <li>Contact</li>
                <li>News</li>
                <li>Events</li>
                <li>Video</li>
                <li>Photos</li>
            </ul>
        </div><!-- navigation -->

The CSS:

#navigation {
    border: 3px solid orange;
    overflow: hidden;
}
#navigation ul {
    list-style-type: none;
    text-align: center;
}
#navigation ul li {
    float: left;
    display: block;
    padding: 10px 8px;
    border: 1px solid green;
}

instead of display:block, use this :

#navigation ul li {
    display:-moz-inline-stack; 
    display:inline-block; 
    zoom:1; 
    *display:inline;
    padding: 10px 8px;
    border: 1px solid green;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM