设置DIV行中最后一个DIV的样式

问题描述 投票:4回答:6

我查了这篇文章(How to style the first and last li with CSS or jQuery?),但仍在寻找合适的IE8(以及IE8之前的)解决方案。

我有一排DIV被设置为具有填充权限,但为了使最终的DIV正确对齐,希望最终的DIV具有零填充。我之前使用过.css + .css路由,但这似乎不适用于IE8和之前的版本。

任何帮助,将不胜感激。

html css css-selectors
6个回答
4
投票

假设包含所有这些的包含div,您应该能够这样做:

div.container {
    background-color: blue;
}
div.container .div-row {
    float: left;
    padding-right: 5px;
}
div.container .div-row:last-child {
    padding-right: 0px;
}

3
投票

你可以给一个类最后一个div,让它在IE中使用该类。

<div class="last"></div>

<style>
    .last
    {
        padding-right:0;
    }
</style>

2
投票

你可以使用类似下面的CSS:

.rowofdivs div:last-child {
    padding-right: 0;
}

1
投票

你可以使用css伪类:last-of-type


1
投票

这是一个CSS3选择器,请参阅quirks mode以获取可用于哪些浏览器的列表。

为什么不在代码中添加class =“last”到最后一个div?

最后一个孩子不适用于IE8及更少


1
投票

如果您无法按照其他答案中的建议手动添加“last”类,则必须依靠JavaScript来完成此操作。如果你有jQuery,你可以这样做:

 $('#parentdiv div:last-child').addClass('last');

然后相应地调整样式表:

 .last { padding-right: 0 }
© www.soinside.com 2019 - 2024. All rights reserved.