Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS nesting rules on same class tag

Tags:

html

css

nested

I have two css styles, the second of which I only want to take effect when the first is present. How would I go about that? I know that you can add more than one class to a class tag, but it doesn't seem to work to nest the css tags the same way.

.stat{float: left; width: 200px; height: 40px; padding: 5px; margin: 5px; border: 1px solid #000;}
.stat .red{background-color: #c00;}


<!-- This should have the background color -->
<div class="stat red">

<!-- This should not have the background color -->
<div class="red">

<!-- This should not have the background color -->
<div class="stat">
like image 458
Ben Dauphinee Avatar asked Jun 28 '26 09:06

Ben Dauphinee


1 Answers

just leave out the space:

.stat.red{background-color: #c00;}
like image 108
newtron Avatar answered Jun 29 '26 23:06

newtron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!