Skip to content Skip to sidebar Skip to footer

Unordered List Navigation With Floating Left And Right Elements

I have a simple navigation bar at the top of the page with several links – the first is floated to the left using li:first child, the last floated to the right using li:last chil

Solution 1:

instead of using

dispaly:inline;

you can use

nav li { float:left; list-style: none; padding : 10px; }
nav li:first-child { margin-right:50px; } nav li:last-child { margin-left:50px; }

Solution 2:

Shreedhar is quite right in that using 'float' is not required – although rather than guessing the margins assigning li:first-child and li:last child absolute positions seems to be a better method – it also seems to work with any number of links in the central block.

nav li {
    display: inline;
    list-style: none;
    text-align: center;
}

nav li:first-child {
    position: absolute;
    left: 20px;
    text-align:left;
}

nav li:last-child {
    position: absolute;
    right: 20px;
    text-align: right;
}

Post a Comment for "Unordered List Navigation With Floating Left And Right Elements"