What does a CSS selector in square brackets select in HTML?

前端 未结 2 2039
时光取名叫无心
时光取名叫无心 2020-12-20 15:34

So I have seen this CSS rule-set in a library:

[text-uppercase] {
   text-transform: uppercase;
}

and I am not sure on how to use it in a <

相关标签:
2条回答
  • 2020-12-20 16:10

    It's not a class, you encountered a so called attribute selector. It matches every html element that has got that attribute set, whatever the value. I.e. <section text-uppercase="true">, <div text-uppercase="something">, <nav text-uppercase>

    Look at the reference provided on the link above for more advanced usage scenarios.

    [text-uppercase] {
      text-transform: uppercase;
    }
    <span text-uppercase>hello</span>

    0 讨论(0)
  • 2020-12-20 16:16

    For the selector to work:
    <div text-uppercase></div>

    [text-uppercase] selector matches an attribute on a tag.

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