I would like to know if it's possible to target all classes that starts with col-
and ends with 12
only?
For example classes like:
.col-sm-12
.col-md-12
.col-lg-12
but not classes like:
.col-sm-8
.col-lg-6
I tried with something like this which is not working:
[class^="col-*-12"] {
border: 1px solid red;
}
Wildcard Selectors (*, ^ and $) in CSS for classesWildcard selector is used to select multiple elements simultaneously. It selects similar type of class name or attribute and use CSS property. * wildcard also known as containing wildcard.
The universal selector is used as a wildcard character.
A wildcard character is used to substitute one or more characters in a string. Wildcard characters are used with the LIKE operator. The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
You can use the following solution:
[class^="col-"][class$="-12"] {
color:red;
}
<span class="col-lg-12">col-lg-12</span>
<span class="col-md-12">col-md-12</span>
<span class="col-lg-8">col-lg-8</span>
<span class="col-md-9">col-md-9</span>
Explanation:
[class^="col-"]
: The class have to start with col-
.[class$="-12"]
: The class have to end with -12
.You can find a very good overview of the attribute pattern on CSS tricks.
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