可以更简洁地编写布尔属性的CSS属性选择器吗? [英] Can CSS attribute selectors for boolean attributes be written more concisely?

查看:357
本文介绍了可以更简洁地编写布尔属性的CSS属性选择器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读HTML布尔属性 (例如 readonly 禁用必需(等))可以为空白或具有其名称的值。而且人们似乎都在使用这两种样式(请参阅如何写入布尔属性)?)...



所以看来最好的方法是编写你的CSS:

 输入[readonly],输入[readonly =readonly] {
}

http://stackoverflow.com/a/19644231/1766230 ) p>

是否有更简洁的写法?可能使用一些CSS3属性选择器魔术?我尝试了输入[readonly * =] ,但没有运气。

解决方案

当@JoshC在注释中写入时,可以使用 input [readonly] 。此CSS选择器(不了解所有标记序列化问题)匹配具有 readonly 属性的输入元素,它的价值是什么。每个属性规范必须包含一个值的XHTML(XML)要求不会影响这一点。


I've read that HTML "boolean attributes" such as readonly, disabled, required (etc.) can either be blank or have a value of their name. And people seem to be using both styles (see How should boolean attributes be written?)...

So it seems that the best way to accommodate this is to write your CSS like:

input[readonly], input[readonly="readonly"] {
}

(http://stackoverflow.com/a/19644231/1766230)

But is there a more concise way to write this? Maybe using some CSS3 attribute selector magic? I've tried input[readonly*=""], but without luck.

解决方案

As @JoshC writes in a comment, you can simply use input[readonly]. This CSS selector (which is ignorant of all markup serialization issues) matches an input element that has the readonly attribute, no matter what its value is. The XHTML (XML) requirement that every attribute specification must include a value does not affect this.

这篇关于可以更简洁地编写布尔属性的CSS属性选择器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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