Why use an attribute selector to match classes?

前端 未结 1 520
北恋
北恋 2020-11-29 20:34

I have found an example of responsive email templates where there are such CSS selectors such as the following:

a[class=\"btn\"]

Why is thi

相关标签:
1条回答
  • 2020-11-29 21:14

    The [] syntax is an attribute selector.

    a[class="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.

    You may want to read The 30 CSS Selectors you Must Memorize. It's invaluable to any up-and-coming web developer.

    0 讨论(0)
提交回复
热议问题