Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript CSS中是否有一种方法可以访问元素中的元素。第一要素,第二要素?_Javascript_Html_Css - Fatal编程技术网

Javascript CSS中是否有一种方法可以访问元素中的元素。第一要素,第二要素?

Javascript CSS中是否有一种方法可以访问元素中的元素。第一要素,第二要素?,javascript,html,css,Javascript,Html,Css,假设我有 <div class='r1'> <div> Apple </div> <div> Banana </div> <div> Orange </div> <div> Tulip </div> </div> .ri:n子项(1){ 颜色:红色;

假设我有

  <div class='r1'>
               <div> Apple </div>
               <div> Banana </div>
               <div> Orange </div>
               <div> Tulip </div>
  </div>
.ri:n子项(1){
颜色:红色;
}
.ri:n个孩子(2){
颜色:蓝色;
}

等等。

您可以使用
:nth-child()
选择器。例如:

.r1:nth-child(1) {
  color: red;
}

.r1:nth-child(2) {
  color: blue;
}
你也可以使用一些很酷的配方食品,比如:

/* Will make every 5th element red, starting at the second one */
.r1:nth-child(5n+1) {
  color: red;
}

/* Will make the odd div elements blue */
.r1:nth-child(odd) div {
  color: blue;
}

了解第N个孩子你是说div。。。
/* Will make every 5th element red, starting at the second one */
.r1:nth-child(5n+1) {
  color: red;
}

/* Will make the odd div elements blue */
.r1:nth-child(odd) div {
  color: blue;
}