[英]Working CSS does not apply to element when using different selectors?
I am working on fixing an issue I am seeing with a textarea
and wysihtml
. 我正在解决通过textarea
和wysihtml
看到的问题。
Currently I have something like this 目前我有这样的事情
<textarea class="wysihtml wysi-fix" required></textarea>
I have some CSS that looks like this 我有一些看起来像这样的CSS
.wysi-fix{
//some css here
}
The .wysi-fix CSS works on the textarea, however if I change the textarea to... .wysi-fix CSS适用于textarea,但是如果我将textarea更改为...
<textarea class="wysihtml" required></textarea>
and I change the CSS to 然后将CSS更改为
.wysihtml[required]{
//the css goes here
}
The CSS no longer works, even though both selectors are selecting the same element on the HTML page. 即使两个选择器都在HTML页面上选择了相同的元素,CSS也不再起作用。 If it helps, I am using SASS instead of vanilla CSS. 如果有帮助,我将使用SASS而不是原始CSS。 Any idea as to what is going on? 关于发生了什么的任何想法?
According to MDN , your attribute selector should work. 根据MDN ,您的属性选择器应该起作用。
Possibly you have to use [required="required"]
as attribute selector with a markup like <textarea class="wysihtml" required="required"></textarea>
: 可能您必须使用[required="required"]
作为带有<textarea class="wysihtml" required="required"></textarea>
这样的标记的属性选择器:
.wysihtml[required="required"]{
//the css goes here
}
But a better way would be to use the :required
pseudo class: 但是更好的方法是使用:required
伪类:
.wysihtml:required{
//the css goes here
}
试试.wysihtml:required
而不是.wysihtml[required]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.