0

我有一个列表,需要它上面的所有其他项目来更改颜色并删除它的边距。我使用了 nth-child,它在除 IE7-8 之外的所有设备上都能完美运行。我知道他们不支持nth-child,所以我使用了Jquery。

我发现这个::nth-​​child 不在 IE 中工作 ,这个:http: //verboselogging.com/2010/01/17/making-nth-child-work-everywhere

我试图实现它们,但它仍然无法正常工作。你可以在这里查看: http ://www.dffernandez.com/client_review_files/tests/nth-child.html

#prop-images-wrapper {
float: left;
margin-bottom: 0.6em;
background-color: #F00;
width: 340px;
margin-right: 5px;}

#prop-images-wrapper li:nth-child(2n+1), .difcolor {
margin-right: 0px;
background-color: #06F;}

--

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>$(document).ready(function(){
$("#prop-images-wrapper li:nth-child(2n+1)").addClass("difcolor");
});</script>

先感谢您。

4

2 回答 2

0

如果您使用 jquery 将第 n 个孩子设置为,只需将 jquery 用于所有内容,而不是为 jquery 使用 css 块和代码。

看看下面的 jsfiddle

http://jsfiddle.net/RjGpC/1/

在下面这一行

#prop-images-wrapper li:nth-child(2n+1), .difcolor {

只需删除li:nth-child(2n+1),

于 2012-11-29T17:24:19.003 回答
0

您忘记在测试页面中加载 jquery。

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

http://jsfiddle.net/m6vnt/1/

于 2012-11-29T17:16:54.823 回答