How to remove margin from last li, in pure CSS with IE 6 support?
In this condition, it is possible not to apply margin-right
to the latter li
.
I need a clean css way and support in IE6 and 7, and also no HTML change . is there any way to achieve this.
ul li {display:inline;margin-right:10px}
<ul id="nav">
<li><a href="#nowhere" >Lorem</a></li>
<li><a href="#nowhere" >Aliquam</a></li>
<li><a href="#nowhere" >Morbi</a></li>
<li><a href="#nowhere" >Praesent</a></li>
<li><a href="#nowhere" >Pellentesque</a></li>
</ul>
a source to share
You can use IE CSS expressions to achieve this.
ul#nav li {
margin-right: 10px;
/* for IE only: */
margin-right: expression(this.nextSibling == null ? '0' : '10px' );
}
/* for standards browsers: */
ul#nav li:last-child {
margin-right: 0;
}
Tested and works in IE7. I don't have access to IE6, but it should work the same way.
If possible it would be better to put the expression rule in an IE-only style sheet.
a source to share
Give the last class <li>
a and then apply margin-right: 0px
to the class.
There is a :last-child
pseudo-class in CSS3 in CSS3, but will not work in IE 6 or 7.
a source to share