使用CSS(SASS)设置禁用或只读元素的所有子元素的样式

时间:2017-03-21 09:51:10

标签: html css sass

如果您能告诉我如何为残疾人或只读DOM-Element的所有孩子设置样式,那将是很好的。

我的HTML代码如下所示:

<div class="wrapper" disabled="disabled">
    <label>
            Test
            <input type="text">
    </label>
</div>

和我的SCSS代码如下:

.wrapper:disabled{
    *{
         background-color: grey;
    }
}

但是.wrapper元素是否被禁用并不重要,.wrapper的明星风格占主导地位。

在父div没有被禁用之前,有没有办法抑制这种风格?

1 个答案:

答案 0 :(得分:2)

.wrapper[disabled] * {
         background-color: grey;
}
<div class="wrapper" disabled="disabled">
    <label>
            Test
            <input type="text">
    </label>
</div>

css选择器应该是.wrapper [disabled]