为什么使用属性选择器来匹配类? [英] Why use an attribute selector to match classes?

查看:100
本文介绍了为什么使用属性选择器来匹配类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了示例,其中有这样的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?

推荐答案

[]语法是

这将选择任何带有class="btn"<a>标签.但是,例如,它将选择具有class="btn btn_red"<a>(而

This will select any <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.

您可能想阅读 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屋!

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