问题描述
我有一个表单,我想将文本框涂成灰色,但是这样做时,提交类型的文本也会变成浅灰色。因此,我决定为类型不等于提交的所有输入制作CSS,但是这样做有麻烦。我知道,如果我想选择所有包含 submit的输入,我应该使用 input [type * = submit]
和不选择特定元素的语法是:not(attribute)
,但是我不知道如何实现类似 input [type:not( submit)
。
I have a form, and I want to gray out the textboxes, but in doing that, the text of the "submit" type goes light gray too. So I decided to make the CSS for all inputs where the type is not equal to "submit", but I'm having problems doing that. I know that if I wanted to select all inputs that contain "submit", I should use input[type*="submit"]
and the syntax to not select a specific element is :not(attribute)
, but I cant figure out how to implement something like input[type:not("submit")
.
input {
color: #666;
}
input[type*="submit"]{
color: #000;
}
<div class="modal-content">
<form action="/action_page.php">
First Name:<br>
<input type="text" name="firstname" value="First Name" title="Type your First Name" onfocus="this.value='';">
<br><br>
Last Name:<br>
<input type="text" name="lastname" value="Last Name" title="Type your Last Name">
<br><br>
Email:<br>
<input type="email" name="email" value="user@email.com" title="Type your email">
<br><br>
Phone:<br> <!--Brazilian pattern (xx)x.xxxx-xxxx-->
<input type="tel" name="phone" pattern="^\(?:\(\d{2}\)|\d{2})[\d{1}][. ]?\d{4}[- ]?\d{4}"value="(xx)x.xxxx-xxxx" title="Type your phone number">
<br><br>
Age:<br>
<input type="age" pattern=".{2,3}" name="idade" value="Age" title="Idade">
<br><br>
<br><br>
<input type="submit" value="Submit">
</form>
</div>
推荐答案
使用:not()
选择器和属性选择器,可以排除 type = submit
。
Using the :not()
selector with the attribute selector, you can exclude type="submit"
from your rule.
input:not([type="submit"]) {
color: red;
}
<input type="text" name="firstname" value="First Name" title="Type your First Name" onfocus="this.value='';">
<input type="text" name="lastname" value="Last Name" title="Type your Last Name">
<input type="email" name="email" value="user@email.com" title="Type your email">
<input type="tel" name="phone" pattern="^\(?:\(\d{2}\)|\d{2})[\d{1}][. ]?\d{4}[- ]?\d{4}" value="(xx)x.xxxx-xxxx" title="Type your phone number">
<input type="age" pattern=".{2,3}" name="idade" value="Age" title="Idade">
<input type="submit" value="Submit">
这篇关于如何选择除type =“ value”以外的所有输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!