Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.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/7/css/37.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
Html 在SASS中,我想更改每一偶数行项目的背景色_Html_Css_Sass - Fatal编程技术网

Html 在SASS中,我想更改每一偶数行项目的背景色

Html 在SASS中,我想更改每一偶数行项目的背景色,html,css,sass,Html,Css,Sass,在SASS中,我想更改每一偶数行项目的背景色 这是我的HTML,显示一行3项的网格视图 <ul> <li><li> <li><li> <li><li> <li><li> <li><li> <li><li> <li><li> <li><li> <li><li> &l

在SASS中,我想更改每一偶数行项目的背景色

这是我的HTML,显示一行3项的网格视图

<ul>
 <li><li> <li><li> <li><li>
 <li><li> <li><li> <li><li>
 <li><li> <li><li> <li><li>
 <li><li> <li><li> <li><li>
</ul>
问题:上述示例是否仅执行第三项

我想要的结果:

.ul {
  li {
    background: $white;

    &:nth-child(3) {
        background: red;
    }
  }
}
每排有三个李 我希望李的每一排都有一个红色的背景色。 为了在SASS中实现这一点,我可以在第n个孩子身上做一些数学题吗?

这一题有效:

ul {
  li {
    background: white;

        &:nth-child(6n-2), &:nth-child(6n-1),&:nth-child(6n) {
        background: red;
    }
  }
}
还请注意,您使用的是
.ul
,而不是
ul

,这一款有效:

ul {
  li {
    background: white;

        &:nth-child(6n-2), &:nth-child(6n-1),&:nth-child(6n) {
        background: red;
    }
  }
}

另请注意,您使用的是
.ul
而不是
ul

@AngularM。请将答案标记为已接受,以便有类似问题的用户更容易决定该解决方案是否可接受them@AngularM请将答案标记为已接受,以便有类似问题的用户更容易决定解决方案是否可行他们可以接受