So, here's a snippet of my HTML:
<div class="stepwizard__step">
<a class="btn btn-primary stepwizard__btn">1</a>
<p class="stepwizard__step-text">Payment</p>
</div>
Basically, what I want to do is, every time there's a Bootstrap primary button (.btn-primary
), I want to change the color of the .stepwizard__step-text
(in this case, "Payment") to red.
Is this possible?
My first instinct was to try something like this:
.btn-primary > .stepwizard__step-text {
color: red;
}
but then I realized that won't work because the stepwizard__step-text
class isn't inside the btn-primary
class.
I realize this is a bit of stretch, but is there a way in CSS to check if the btn-primary
class exists inside of stepwizard__step
and if it does, to change the color of stepwizard__step-text
to red? If not, can anyone think of another way to do this?
Unfortunately, CSS does not provide 'inheritance' in the way that programming languages like C++, C# or Java do. You can't declare a CSS class an then extend it with another CSS class.
Instead of calling those classes in the html, we will tell the class to inherit the rules into its styling. In order to @extend the styling rules of a css class into another, you use the syntax @extend . classname; . This should be added to .
HTML elements can be assigned multiple classes by listing the classes in the class attribute, with a blank space to separate them.
CSS nesting provides the ability to nest one style rule inside another, with the selector of the child rule relative to the selector of the parent rule. Similar behavior previously required a CSS pre-processor.
The element>element selector is used to select elements with a specific parent.
Note: Elements that are not directly a child of the specified parent, are not selected.
So, you must use +
Selector :
The element+element selector is used to select elements that is placed immediately after (not inside) the first specified element.
Read More :
https://www.w3schools.com/cssref/sel_element_gt.asp
In your Case Change Code Like:
.btn-primary + p.stepwizard__step-text {
color: red;
}
<div class="stepwizard__step">
<a class="btn btn-primary stepwizard_btn">1</a>
<p class="stepwizard__step-text">Payment</p>
</div>
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