问题描述
给定不同类型的这些HTML输入
:
<input type="text" id="username" />
<input type="email" id="emailaddress" />
<input type="date" id="birthday" />
<input type="password" id="pword" />
<input type="search" id="q" />
可以将CSS样式应用于所有文本框或者为每个类添加一个类或者选择它们,如下所示:
Is it possible to apply CSS styles to all text boxes without having to either add a class to each or selecting them like this:
input[type="text"],
input[type="email"],
input[type="date"],
input[type="password"],
input[type="search"]
...
此外,我不想使用 input {}
,因为当我只想要的样式是文本框时,将选择单选按钮等。
Also I don't want to use input { }
as that would select radio buttons etc. when I only want to style are the text boxes.
推荐答案
我不认为这是可能的。例如,由浏览器决定如何呈现输入。没有办法查询浏览器如何渲染控件(据我所知)。
例如,某些浏览器会将范围输入呈现为文本框,而不是滑块。另外一些浏览器渲染'搜索'控件不同于其他文本框(圆角等),所以你的CSS可能不会按照你的期望工作。
I don't think this is possible. For instance, it's up to the browser to decide how an input is rendered. There's no way to query how the browser has rendered a control (as far as I know).For example, some browsers will render a 'range' input as as textbox rather than a slider. Also some browsers render the 'search' control differently to other text boxes (rounded corners etc), so your CSS may not work as you expect anyway.
必须去输入[type =text],input = [type =password] {}规则。
I think you'll have to go for the input[type="text"], input=[type="password"] { } rules as you described.
这篇关于有没有办法将CSS应用到所有HTML5文本输入,而不管类型属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!