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 属性选择器:引号的规则(“,"还是没有?
基础教程推荐
- 直接将值设置为滑块 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01