简体   繁体   English

带有必需属性的W3C CSS Validator错误

[英]W3C CSS Validator error with required attribute

I'm getting the following error in the W3C CSS 3 Validator: 我在W3C CSS 3 Validator中收到以下错误:

Unknown pseudo-element or pseudo-class :required 未知的伪元素或伪类:必需

Required is a HTML5 input attribute. 必需是HTML5输入属性。 My CSS works in IE10, Google Chrome and Firefox. 我的CSS适用于IE10,谷歌浏览器和Firefox。

This is my CSS: 这是我的CSS:

#reserved input:required {background:#eaeae6;}
#reserved select:required {background:#eaeae6;}

This is my HTML code: 这是我的HTML代码:

<section id="reserved">
    <select id="hab" name="hab" title="Study or Apartment" required>
    <input type="text" id="name" name="name" maxlength="50" style="width: 200px;" title="Name and Surname" required/>
</section>

Doesn't W3C recognize the required attribute like a standard? W3C不能像标准一样识别所需的属性吗?

CSS3 includes the Selectors Level 3 API. CSS3包括Selectors Level 3 API。 Selectors 3 does not include the :required selector. 选择器3不包括:required选择器。

:required was introduced in Selectors Level 4 . :requiredSelectors Level 4中引入。 Browsers support it, but it isn't part of the CSS3 specification and so will fail in a CSS3 validator. 浏览器支持它,但它不是CSS3规范的一部分,因此在CSS3验证器中会失败。

Thanks for your answer lonesomeday. 谢谢你的回答lonesomeday。

I change my css and create a class instead of the required pseudo-class like this: 我更改了我的CSS并创建了一个类而不是像这样所需的伪类:

#reserved .required-class {background: #eaeae6;}

<input class="required-class" type="email" id="email" name="email" pattern="[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*@[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{1,5}" style="width: 200px;" title="email" required/>

With this change, now I've passed the W3C Validator :D 有了这个改变,现在我已经通过了W3C Validator:D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM