使用CSS3选择除按钮之外的每个表单元素

Gab*_*ias 7 css css-selectors css3

是否有与CSS3的方式来选择,它的每个输入有关的要素具有type的属性button,reset,submit,或的标签button?这是我到目前为止所得到的:

input:not([type="submit"]),
textarea {

    /* ... */

}

input:not([type="submit"]):focus,
textarea:focus {

    /* ... */

}

input:not([type="submit"]):hover,
textarea:hover {

    /* ... */

}
Run Code Online (Sandbox Code Playgroud)

......但它并不像它那样普遍.我想将一些不错的新转换应用于仅与输入相关的字段.如果这些特定样式应用于页面上的任何按钮,它开始看起来很奇怪.任何帮助表示赞赏.

0b1*_*011 19

只需将多个:not选择器链接在一起:

/* Fields */
input:not([type=button]):not([type=reset]):not([type=submit]):not([type=image]),
textarea {
  outline: 3px solid green;
}

/* Buttons */
input[type=button],
input[type=reset],
input[type=submit],
input[type=image],
button {
  outline: 3px solid red;
}

/* Both */
input,
button,
textarea {
  margin: 6px;
}
Run Code Online (Sandbox Code Playgroud)
<h1>Form elements</h1>
<p>Buttons should be outlined in red, fields in green.</p>
<button>Button</button>
<input type="button" value="Input Button">
<input type="checkbox">
<input type="color">
<input type="date">
<input type="datetime-local">
<input type="email">
<input type="file">
<input type="hidden">
<input type="image" src="//placehold.it/100x40/ffff00/0000ff/?text=foo">
<input type="month">
<input type="number">
<input type="password">
<input type="radio">
<input type="range">
<input type="reset">
<input type="search">
<input type="submit">
<input type="tel">
<input type="text">
<input type="time">
<input type="url">
<input type="week">
<textarea></textarea>
Run Code Online (Sandbox Code Playgroud)