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

查看:33
本文介绍了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 属性的输入框(因为它默认为 text 但 input[type='text'] 不匹配).不幸的是,我在 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?

推荐答案

:not 选择器:

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天全站免登陆