CSS属性选择器:引号上的规则("','或none?) [英] CSS attribute selectors: The rules on quotes (", ' or none?)
问题描述
这个问题已经扰乱我一段时间了。当写一个CSS选择器与一个元素的属性比较如此。
a [rel =nofollow]
我从来不知道我应该用什么引号。他们真的有必要吗?
基本上,这是什么规格,因为我不能在网站上找到它。
这些都被视为有效吗?
a [rel =nofollow]
a [rel ='nofollow']
a [rel = nofollow]
我在此处更详细地介绍了此主题:
只要属性值是字母数字,通常可以省略引号(但是,有一些例外 - 有关所有详细信息,请参阅链接文章)。无论如何,我发现这是一个好的做法,无论如何添加引号,如果你需要它们,即 a [href ^ = http://]
将无法工作, a [href ^ =http://]
将。
CSS规范中的章节。
This question has been bugging me for a while now. When writing a CSS selector that compares against an element's attribute like so.
a[rel="nofollow"]
I never know what I should be doing with the quotation marks. Are they really necessary?
Basically, what is the specification for this because I can't find it on the web site.
Are all of these considered valid?
a[rel="nofollow"]
a[rel='nofollow']
a[rel=nofollow]
I’ve written more extensively on the subject here: Unquoted attribute values in HTML and CSS.
I’ve also created a tool to help you answer your question: http://mothereff.in/unquoted-attributes
You can usually omit the quotes as long as the attribute value is alphanumeric (however, there are some exceptions — see the linked article for all the details). Anyhow, I find it to be good practice to add the quotes anyway in case you need them, i.e. a[href^=http://]
won’t work, but a[href^="http://"]
will.
The article I mentioned links to the appropriate chapters in the CSS spec.
这篇关于CSS属性选择器:引号上的规则("','或none?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!