I inherited some css and I have searched everywhere online to understand what is being expressed by a block of css that looks like:
[class*=wrapper] .logo {
padding-top: 32px !important;
}
What is the asterisk and square brackets doing?
It is hard to search for [ and * on google... Sorry if the question is dumb.
[class*="button_type"] is CSS class Selector (equivalent to CSS attribute selector) means that will select all elements whose class contains at least one substring "button_type".
A CSS class is an attribute used to define a group of HTML elements in order to apply unique styling and formatting to those elements with CSS.
To select elements with a specific class, write a period (.) character, followed by the name of the class. You can also specify that only specific HTML elements should be affected by a class. To do this, start with the element name, then write the period (.)
CSS Class Example You can also select elements (or classes) that's nested within another element or class. For example, div. css-section p will select all <p> elements that are nested within a <div> element that uses the . css-section class.
It selects an element with class logo
that has an ancestor that has wrapper
somewhere in its class attribute. For example note that the class burgerwrapper
also leads to the element being selected below.
[class*=wrapper] .logo {
color: #f99;
}
<div class="logo">Not selected</div>
<div class="wrapper">
<div class="logo">
Selected
</div>
</div>
<div class="burgerwrapper">
<div class="logo">
Selected
</div>
</div>
See http://css-tricks.com/attribute-selectors/ for some background information on attribute selectors.
what square brackets doing
Attribute selectors
CSS 2.1 allows authors to specify rules that match elements which have certain attributes defined in the source document.
Attribute selectors w3
What is the asterisk
Substring matching attribute selectors
[att*=val] Represents an element with the att attribute whose value contains at least one instance of the substring "val". If "val" is the empty string then the selector does not represent anything.
Substring matching attribute selectors
To sum it up in you example:
[class*=wrapper] .logo {
color: red;
}
<div class="wrapper">
<div>not this</div>
<div class="logo">this</div>
<div class="logo">this</div>
</div>
<div>
<div>not this</div>
<div class="logo">not this</div>
<div>not this</div>
</div>
Select child elements with class .logo
that their parent element has attribute class with value wrapper
appears somewhere in that attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With