If you don't need to worry about old browsers, use the :first-child
and :last-child
pseudo-classes on the list items, like so:
/* Because we are looking at the <li> children of your <ul> */
.menu ul li:first-child a {}
.menu ul li:last-child a {}
However, support for CSS3 :last-child
is pretty poor right now, so a more browser-compatible alternative is to manually give the last list item a last
class, like so (and doing the same for first):
<ul>
<li class="first"><a href="#">HOME</a></li>
<li><a href="#">LINK</a></li>
<li><a href="#">LINK</a></li>
<li><a href="#">LINK</a></li>
<li class="last"><a href="#">LINK</a></li>
</ul>
Then, you can use these selectors:
.menu ul li.first a {}
.menu ul li.last a {}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…