Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 div

<div class="text-uppercase | [text-uppercase]"></div>

I have tried both, but neither are working. I am seeing this in ionic2.

like image 493
Cozzbie Avatar asked Oct 06 '16 11:10

Cozzbie


People also ask

What does square brackets mean in CSS?

The square brackets are used as an attribute selector, to select all elements that have a certain attribute value. In other words, they detect attribute presence.

What is CSS selector in HTML?

A CSS selector is the first part of a CSS Rule. It is a pattern of elements and other terms that tell the browser which HTML elements should be selected to have the CSS property values inside the rule applied to them.

How do you make a square bracket in CSS?

Square brackets are attribute selector syntax. Show activity on this post. The selector you've given in the question means it would need all three words: The element name 'input', the attribute 'type' and the value for that attribute being 'radio'.

How do you put square brackets in HTML?

] - right square bracket (U+005D) - HTML Symbols.


2 Answers

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

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

like image 197
George Kagan Avatar answered Oct 05 '22 23:10

George Kagan


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>
like image 26
christo Avatar answered Oct 05 '22 23:10

christo