Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align one of several <li> to the right?

    <div id="menu">
<ul><li><a href="#" class="current">SocialSpot</a></li>
<li><a href="#">Profile</a></li>
<li><a href="#">Latest</a></li>
<li><a href="#">Settings</a></li>
<li>Logout</li>
    </div>
    </ul>

I have this in a webpage. I have css aligning them. However I want the logout button to be aligned to the right but on the same bar. How can I do this without having them all aligned to the right?

like image 603
Michael Avatar asked Mar 04 '11 19:03

Michael


1 Answers

CSS:

ul { overflow:auto; }
li { float:left; }
li:last-child { float:right; }

Live demo: http://jsfiddle.net/simevidas/Rs4Sa/


Btw the :last-child pseudo-class does not work in IE8 (and below). If you want it to work in those browsers, you will have to assign a class (e.g. right) to the Logout LI item, and then:

li.right { float:right; }

Live demo: http://jsfiddle.net/simevidas/Rs4Sa/1/

like image 150
Šime Vidas Avatar answered Oct 05 '22 23:10

Šime Vidas