类的方括号选择器 [英] Square brackets selector for classes

查看:351
本文介绍了类的方括号选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了示例的响应式电子邮件模板,其中有诸如以下CSS声明之类的CSS声明:

I have found an example of responsive email templates where there are such CSS declarations 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?

推荐答案

[] 语法是属性选择器

a[class="btn"]

这将选择< a> 标记与 class =btn。但是,不会选择 class =btn btn_red< a> >,例如(而 a.btn 会)。

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选择器。这对任何即将到来的网络开发者来说都是无价的。

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天全站免登陆