CSS attribute selectors: The rules on quotes (quot;, #39; or none?)(CSS 属性选择器:引号的规则(“,还是没有?))
问题描述
这个问题已经困扰了我一段时间了.当编写一个 CSS 选择器来比较一个元素的属性时.
a[rel="nofollow"]
我从来不知道我应该用引号做什么.它们真的有必要吗?
基本上,这是什么规格,因为我在网站上找不到.
所有这些都被认为是有效的吗?
a[rel="nofollow"]a[rel='nofollow']一个 [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 属性选择器:引号的规则(“,"还是没有?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CSS 属性选择器:引号的规则(“,"还是没有?


- 失败的 Canvas 360 jquery 插件 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07