Html 更改特定的div,nth-child?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14449006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change specific div, nth-child?
提问by Kim Kakan Andersson
I have a problem here. I have this div
that's mentioned 4 times in my code, like:
我这里有问题。我div
的代码中提到了 4 次,例如:
<div class='box1'>
Hello 1
</div>
<div class='box1'>
Hello 2
</div>
<div class='box1'>
Hello 3
</div>
<div class='box1'>
Hello 4
</div>
and I want to do some changes to this div
class, but only the last one. I cant get the nth-class to work, it seems that i need to make a ul
table for it to work? Can I get a workaround somewhere in the CSSand make it work without having to rewrite my code?
我想对这个div
类做一些改变,但只有最后一个。我不能让第n级工作,看来我需要做一张ul
桌子才能工作?我可以在CSS 中的某处找到解决方法并使其工作而不必重写我的代码吗?
回答by Sheixt
You should be able to do this with the nth-child
pseudo class. Take a look at this demo: http://jsfiddle.net/m7uW7/2/
您应该能够使用nth-child
伪类来做到这一点。看看这个演示:http: //jsfiddle.net/m7uW7/2/