- <html>
- <head>
- <meta charset="utf-8">
- <meta name="" content="content">
- <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
- <title></title>
- <link rel="stylesheet" type="text/css" href="">
- <script src="js/jquery1.8.3.min.js"></script>
- </head>
- <script>
- /*$(document).ready(function(){
- $(‘.product_tit:even‘).css({"color":"#21c178"});
- $(‘.product_tit:odd‘).css({"color":"#459ee6"});
- })*/
- </script>
- <div> <span style="white-space:pre"> </span><style>
- <span style="white-space:pre"> </span>#list2:nth-of-type(odd) .product_tit{color:#21c178}
- <span style="white-space:pre"> </span>#list2:nth-of-type(even) .product_tit{color:#459ee6}
- <span style="white-space:pre"> </span></style> </div> <body>
- <style type="text/css">
- .list1:nth-of-type(odd){ color:#ffcc00;}
- .list1:nth-of-type(even){ color:#00ccff;}
- </style>
- <div>
- <ul>
- <li class="list1">111111111111111111111111111</li>
- <li class="list1">222222222222222222222222222</li>
- <li class="list1">333333333333333333333333333</li>
- <li class="list1">444444444444444444444444444</li>
- <li class="list1">555555555555555555555555555</li>
- <li class="list1">666666666666666666666666666</li>
- </ul>
- <hr />
- <div id="list2">
- <div class="product_tit">7777777777777777777777777777</div>
- </div>
- <div id="list2">
- <div class="product_tit">8888888888888888888888888888</div>
- </div>
- <div id="list2">
- <div class="product_tit">9999999999999999999999999999</div>
- </div>
- <div id="list2">
- <div class="product_tit">0000000000000000000000000000</div>
- </div>
- <div id="list2">
- <div class="product_tit">7777777777777777777777777777</div>
- </div>
- </div>
- </body>
- </html>
备注:自己添加jquery
错误的css:
[html] view plain copy
- <style>
- .product_tit:nth-of-type(odd){color:#21c178}
- .product_tit:nth-of-type(odd){color:#459ee6}
- </style>
错误的原因:class=product_tit的每个元素都没有兄弟节点,nth-of-type并不会起作用
时间: 2024-11-05 20:46:10