css选择器来匹配没有属性x的元素 [英] css selector to match an element without attribute x

查看:94
本文介绍了css选择器来匹配没有属性x的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个CSS文件,并发现需要样式的文本输入框,但是,我遇到了问题。我需要一个简单的声明,匹配所有这些元素:

I'm working on a CSS file and find the need to style text input boxes, however, I'm running into problems. I need a simple declaration that matches all these elements:

<input />
<input type='text' />
<input type='password' />

...但不匹配这些:

... but doesn't match these ones:

<input type='submit' />
<input type='button' />
<input type='image' />
<input type='file' />
<input type='checkbox' />
<input type='radio' />
<input type='reset' />

这里是我想做的:

input[!type], input[type='text'], input[type='password'] {
   /* styles here */
}

在上面的CSS中,注意第一个选择器是 input [!type] 。我的意思是,我想选择所有的输入框中的type属性没有指定(因为它默认为文本,但 input [type ='text'] doesn' t匹配它)。不幸的是,在CSS3规范中没有这样的选择器,我可以找到。

In the above CSS, notice the first selector is input[!type]. What I mean by this is I want to select all input boxes where the type attribute is not specified (because it defaults to text but input[type='text'] doesn't match it). Unfortunately, there is no such selector in the CSS3 spec that I could find.

有没有人知道一种方法来完成这个?

Does anyone know of a way to accomplish this?

推荐答案

:不选择器

input:not([type]), input[type='text'], input[type='password'] {
   /* style here */
}

支持:在Internet Explorer 9及更高版本

Support: in Internet Explorer 9 and higher

这篇关于css选择器来匹配没有属性x的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆