一般文本框的CSS选择器

Mr *_*ter 5 html css input css-selectors

有没有办法用CSS选择器选择每种文本框,例如给它们提供相同的宽度?通过文本框,我只是指用户可以键入的内容.

我的问题是,有这么多.它过去相当简单; 你只有2种类型的HTML4文本框.这两种类型是textpassword,所以CSS可以

input:not([type]), input[type='text'], input[type='password'] {...}
Run Code Online (Sandbox Code Playgroud)

这将涵盖所有类型.然而,随着HTML5的发明,你会得到更多的类型,比如number,email,url,search并且tel,所有的外观和行为一样(除了你在做什么应该键入它们),我想解决这些问题所有这些都通过CSS以同样的方式.

是否绝对有必要写下这一切?

input:not([type]),
input[type='text'],
input[type='password'],
input[type='number'],
input[type='email'],
input[type='url'],
input[type='search'],
input[type='tel'] {...}
Run Code Online (Sandbox Code Playgroud)

是否可能有更多代码有效的方式来编写它?

Blo*_*sie 5

有更健全的解决方案吗?

一个好的旧时尚课怎么样?

<input class='text' type='text'>

或覆盖非文本的类型

input {
    background: red;
}

input[type=radio], input[type=checkbox], input[type=submit] {
    background: yellow;
}
Run Code Online (Sandbox Code Playgroud)

另外:在我的书中,您的解决方案没有任何问题.

您只需要添加新的输入类型:

  • 颜色
  • 日期
  • 约会时间
  • 日期时间本地
  • 电子邮件
  • 范围
  • 搜索
  • 联系电话
  • 时间
  • 网址

  • 您也可以反转此逻辑并使用:不再:`input:not([type = radio],[type = checkbox],[type = submit],[type = file]) (2认同)