最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Align one of several <li> to the right? - Stack Overflow

programmeradmin0浏览0评论
    <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?

    <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?

Share Improve this question edited Sep 16, 2014 at 22:53 BradleyDotNET 61.3k10 gold badges105 silver badges124 bronze badges asked Mar 4, 2011 at 19:53 MichaelMichael 5732 gold badges12 silver badges26 bronze badges 4
  • What do you mean 'aligning them'? Are you displaying them all horizontally? – Eric Di Bari Commented Mar 4, 2011 at 19:55
  • you can add a class to that li and create a css rule for the class. – Brandon Frohbieter Commented Mar 4, 2011 at 19:56
  • I am using them horizontally yes. – Michael Commented Mar 4, 2011 at 19:56
  • Creating a jsFiddle example will drastically increase your chances of getting a good answer. – thirtydot Commented Mar 4, 2011 at 19:58
Add a comment  | 

3 Answers 3

Reset to default 10

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/

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

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

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

发布评论

评论列表(0)

  1. 暂无评论