css - SCSS中嵌套元素+元素选择器

标签 css sass css-selectors

作为 SCSS 的新手,我想知道如何将它的嵌套用于 element + element CSS 选择器。通常,在 CSS 中,我会这样写:

.test{
    color: red;
}
.test + label{
    color: blue;
}

如何将 + label 选择器嵌套在 .test 选择器中?提前致谢!

最佳答案

更新:在这种情况下,您需要做的就是像这样嵌套规则:

.test {
    color: red;
    + label {
        color: blue;
    }
}

但是,您也可以使用 & 选择器来实现相同的效果,如下所示:

.test {
    color: red;
    & +label {
        color: blue;
    }
}

关于css - SCSS中嵌套元素+元素选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38617842/

相关文章:

html - 将错误文本构建到输入组中

html - 样式表不适用于 Firefox,但适用于 Chrome/IE?

html - 仅显示每个类别的第一个元素

动态添加元素时,CSS nth-child 属性无法正常工作

javascript - 尝试使用 Nightwatch.js 单击具有相同类的第二个元素

html - 删除 Bootstrap 导航栏上的顶部填充

html - 使用 CSS Floats(或其他方法)修复此网格

css - Gulpfile 关键 CSS 解决方案

css - 我可以更改 Angular 2 中的 scss 文件的变量吗

php - 使用 Haml/Sass 的 Wordpress