Skip to content Skip to sidebar Skip to footer

How Can I Select All Elements Except Those Inside Divs With Particular Classes

I'd like to find a way to select all the makes of cars except those that are inside a div with the class discontinued or scrapped. Here's my markup: As you can see above, I tried

Solution 1:

Unfortunately CSS selectors cannot traverse up parent elements, so if you are just trying to style them differently you may want to reverse your thought process and select ones that are.discontinued or .scrapped and apply overriding styles:

.model {
  padding-left: 10px;
}

.make {
  color: green;
}

.scrapped.make,
.discontinued.make {
  color: red;
}
<divclass="car"><divclass="make">NISSAN</div><divclass="model">MICRA</div></div><divclass="discontinued"><divclass="car"><divclass="make">FORD</div><divclass="model">MONDEO</div></div></div><divclass="scrapped"><divclass="car"><divclass="make">SEAT</div><divclass="model">IBIZA</div></div></div><divclass="scrapped"><divclass="preowned"><divclass="car"><divclass="make">SEAT</div><divclass="model">IBIZA</div></div></div></div><divclass="car"><divclass="make">HONDA</div><divclass="model">INTEGRA</div></div><divclass="car"><divclass="make">PEUGEOT</div><divclass="model">206</div></div><divclass="car"><divclass="make">TOYOTA</div><divclass="model">COROLLA</div></div>

Post a Comment for "How Can I Select All Elements Except Those Inside Divs With Particular Classes"