I just saw this code.
.link--icon [class*='text'] {
padding-left: 8px;
}
What does this line .link--icon [class*='text']
exactly mean?
I just saw this code.
.link--icon [class*='text'] {
padding-left: 8px;
}
What does this line .link--icon [class*='text']
exactly mean?
It is an attribute wildcard selector. It looks for a child element under .link--icon
whose class name contains "text".
Example:
div[class*="test"] {
background: #ffff00;
}
<div class="first_test">The first div element.</div>
<div class="second">The second div element.</div>
<div class="test">The third div element.</div>
<p class="test">This is some text in a paragraph.</p>
Here we have three divs, two divs' classes contain the "test" keyword, so those divs' background is set to "#FFFF00". The middle div doesn't, and the p element doesn't match the div rule, so those are not affected.
Refer to this w3schools snippet and this question.
.link--icon [class*='text']
-> Selects every child element of the elements with class link--icon
, whose class
attribute value contains the substring text
.
The [class*='text']
selector combines descendant and attribute selectors, and matches any element that has the class"text"
set (for example: <p class="text">
) and *
is a wildcard that matches any element.
It means that the specified style will be applied to every element that has any class that contains "text" and is a child of an element with "link--icon" defined at the class attribute.
.class: selector for elements by class
[class*='text'] wild card class selector for elements whose defined class contains the substring 'text'
I have the following elements
<input name="man-news">
<input name="milkman">
<input name="letterman2">
<input name="newmilk">
If I use the following selector in a css rule: input[name*='man']
I will apply the rule to the following elements:
<input name="man-news">
<input name="milkman">
<input name="letterman2">