Reputation: 11373
I need to target a <section>
with a specific ID that will show up once in every page. But each will have a unique class. Some of the styles for the section will not apply if that class is added dynamically. Trying to figure out how to best nest the styling using Sass.
Here is a demo on CodePen.
Because it has the class of .soldout
, the background should be grey not red.
<section id="featured-product" class="soldout">
<h1>This car is no longer avaiable</h1>
<img src="https://img.gta5-mods.com/q95/images/2013-lamborghini-veneno-hq-digitaldials/bb4811-venenomain.jpg">
</section>
#featured-product {
/* these styles always apply */
color: #f1f1f1;
font-family: 'Oswald', sans-serif;
text-align:center;
/* These classes should not apply if the section has a class of .soldout */
background: #FC332E;
padding: 25px 30px 45px;
& .soldout {
/* These styles only apply when the element has matching ID and this class added in*/
background: #BDBEBA;
padding: 25px;
}
img { width: 400px; }
}
Upvotes: 0
Views: 1987
Reputation: 354
Remove the space between & and .soldout {
&.soldout {
The way you had it, was you were looking for .soldout WITHIN #featured-product because you had the space.
You weren't looking for #featured-product WITH the class of .soldout
Upvotes: 3