Michael
Michael

Reputation: 573

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?

Upvotes: 8

Views: 34363

Answers (3)

Šime Vidas
Šime Vidas

Reputation: 185963

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/

Upvotes: 10

user228534
user228534

Reputation:

You might want float: right on the css for the logout link.

Upvotes: 1

quarkdown27
quarkdown27

Reputation: 648

Like this? http://jsfiddle.net/QAjkP/

You can use an id tag to specify the css properties for that one <li> item

Upvotes: 0

Related Questions