:第一个孩子伪类不工作
问题描述:
我有一个两个divs shoots
的类。我想第一个div的padding-top
为10px,最后一个div的padding-bottom
为10px。:第一个孩子伪类不工作
为此,我尝试使用伪类选择器:first-child
& :last-child
。
last-child
工程,我有我的填充在div的底部,但first-child
不起作用。
我在做什么错?
标记:
<div class="item-list">
<div class='item'>
<div class="shoots">
*content*
</div>
<div class="shoots">
*content*
</div>
</div>
</div>
CSS
.item-list .item .shoots:first-child
{
padding-top: 10px;
}
.item-list .item .shoots:last-child
{
padding-bottom: 10px;
}
答
尝试只是在做:
.shoots:first-child{
padding-top: 10px;
}
.shoots:last-child{
padding-bottom: 10px;
}
答
:第一胎&:最后一个孩子。不要在块元素上工作,他们只能在内联元素上工作
您使用的浏览器是什么? – Interrobang 2012-02-26 09:25:31
适用于此:http://jsfiddle.net/gBSyh/需要有关您的问题的更多信息。 – 2012-02-26 09:27:04
您发布的代码按预期工作。请尝试扩展您的测试用例,或者提供问题突出的链接/ – 2012-02-26 09:32:28