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

navli { float:left; list-style: none; padding : 10px; }
navli:first-child { margin-right:50px; } navli: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.

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

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

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

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