input[type='text'] CSS selector does not apply to default-type text inputs?

后端 未结 5 1244
醉梦人生
醉梦人生 2021-02-02 05:26

The default input type is \'text\'. I have always assumed then that CSS declarations targeting input[type=\'text\'] would affect those inputs even if the type was n

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-02 05:39

    By CSS specifications, browsers may or may not use information about default attributes; mostly the don’t. The relevant clause in the CSS 2.1 spec is 5.8.2 Default attribute values in DTDs. In CSS 3 Selectors, it’s clause 6.3.4, with the same name. It recommends: “Selectors should be designed so that they work whether or not the default values are included in the document tree.”

    It is generally best to explicitly specify essential attributes such as type=text instead of defaulting them. The reason is that there is no simple reliable way to refer to the input elements with defaulted type attribute.

提交回复
热议问题