admin 管理员组文章数量: 1086019
I'm using the Topcoat CSS library. You can see the code snippet I'm having problems with here.
In the style sheet, there is the following to put a red border around an input when invalid:
.topcoat-text-input--large:invalid {
border: 1px solid #EC514E;
}
My HTML content is:
<input type="text" class="topcoat-text-input--large" id="email" placeholder="email" value="<%= model.email %>">
How do I set the input to use the CSS for invalid? If I change the class of the input from:
topcoat-text-input--large
to
topcoat-text-input--large:invalid
I don't get the red border. How can I use this CSS?
I'm using the Topcoat CSS library. You can see the code snippet I'm having problems with here.
In the style sheet, there is the following to put a red border around an input when invalid:
.topcoat-text-input--large:invalid {
border: 1px solid #EC514E;
}
My HTML content is:
<input type="text" class="topcoat-text-input--large" id="email" placeholder="email" value="<%= model.email %>">
How do I set the input to use the CSS for invalid? If I change the class of the input from:
topcoat-text-input--large
to
topcoat-text-input--large:invalid
I don't get the red border. How can I use this CSS?
Share Improve this question edited Jun 19, 2022 at 11:54 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Mar 24, 2014 at 21:21 user1716672user1716672 1,0732 gold badges22 silver badges45 bronze badges2 Answers
Reset to default 7The :invalid
pseudo-class is triggered when the pattern
input attribute is not matched.
In the linked example:
<input type="text" class="topcoat-text-input--large" placeholder="text" value="fail" pattern="not-fail">
If you type "not-fail" into the box, it will turn blue. If you type anything else, it does not match the pattern
and is invalid
.
For more information, see the MDN article on pattern
.
A regular expression that the control's value is checked against. The pattern must match the entire value, not just some subset. Use the title attribute to describe the pattern to help the user. This attribute applies when the value of the type attribute is text, search, tel, url or email; otherwise it is ignored. The regular expression language is the same as JavaScript's. The pattern is not surrounded by forward slashes.
The :invalid part of the selector is not part of the class, but something called a pseudo class. In the case of :invalid, it only activates when (from MDN):
an
<input>
or<form>
element whose content fails to validate according to the input's type setting.
本文标签: javascriptCSS class with colonStack Overflow
版权声明:本文标题:javascript - CSS class with colon - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744028590a2521080.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论