我查了这篇文章(How to style the first and last li with CSS or jQuery?),但仍在寻找合适的IE8(以及IE8之前的)解决方案。
我有一排DIV被设置为具有填充权限,但为了使最终的DIV正确对齐,希望最终的DIV具有零填充。我之前使用过.css + .css路由,但这似乎不适用于IE8和之前的版本。
任何帮助,将不胜感激。
假设包含所有这些的包含div,您应该能够这样做:
div.container {
background-color: blue;
}
div.container .div-row {
float: left;
padding-right: 5px;
}
div.container .div-row:last-child {
padding-right: 0px;
}
你可以给一个类最后一个div,让它在IE中使用该类。
<div class="last"></div>
<style>
.last
{
padding-right:0;
}
</style>
你可以使用类似下面的CSS:
.rowofdivs div:last-child {
padding-right: 0;
}
你可以使用css伪类:last-of-type
如果您无法按照其他答案中的建议手动添加“last”类,则必须依靠JavaScript来完成此操作。如果你有jQuery,你可以这样做:
$('#parentdiv div:last-child').addClass('last');
然后相应地调整样式表:
.last { padding-right: 0 }