tags:

views:

46

answers:

1

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;
}
A: 

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;
}
Puaka
This works well, but two questions:1. Is this compatible on all major browsers?2. It creates a small margin between the list items, any way to get rid of that.
Jack
sure. just add margin to your #navigation ul : saymargin:10px;
Puaka
note that you can also add margin to your li, should fix the gap problem in IE
Puaka
Sorry, I should have mentioned. I made my comments after trying to add margin: 0 to my li style - doesn't get rid of the margins. If you run the code in firefox or IE 8 the margin problem is present. In IE 7 there are no extra margins. I want it to be that way (like IE 7) for the other browsers as well.I just don't understand why the lists have extra margins when none were added in the css.
Jack