为什么使用属性选择器来匹配类? [英] Why use an attribute selector to match classes?
问题描述
我找到了示例,其中有这样的CSS选择器,如下所示:
I have found an example of responsive email templates where there are such CSS selectors such as the following:
a[class="btn"]
为什么使用与以下语法完全相同的语法:
Why is this syntax used if it's totally the same as:
a.btn
它对移动浏览器或其他任何东西有影响吗?
Does it have any impact on mobile browsers or anything else?
推荐答案
这将选择任何带有 This will select any 您可能想阅读 30种CSS您必须记住的选择器.对于任何有前途的Web开发人员来说,这都是无价之宝. You may want to read The 30 CSS Selectors you Must Memorize. It's invaluable to any up-and-coming web developer. 这篇关于为什么使用属性选择器来匹配类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋![]
语法是
class="btn"
的<a>
标签.但是,例如,它将不选择具有class="btn btn_red"
的<a>
(而<a>
tag with class="btn"
. However, it will not select <a>
which has class="btn btn_red"
, for example (whereas a.btn
would). It only exactly matches that attribute.