Is it possible to define a CSS style for an element, that is only applied if the matching element contains a specific element (as the direct child item)?
I think this is best explained using an example.
Note: I'm trying to style the parent element, depending on what child elements it contains.
<style>
/* note this is invalid syntax. I'm using the non-existing
":containing" pseudo-class to show what I want to achieve. */
div:containing div.a { border: solid 3px red; }
div:containing div.b { border: solid 3px blue; }
</style>
<!-- the following div should have a red border because
if contains a div with class="a" -->
<div>
<div class="a"></div>
</div>
<!-- the following div should have a blue border -->
<div>
<div class="b"></div>
</div>
Note 2: I know I can achieve this using javascript, but I just wondered whether this is possible using some unknown (to me) CSS features.
ol < li:nth-child(n+10) { margin-left: 2rem; } ol < li:nth-child(n+100) { margin-left: 3rem; } ol < li:nth-child(n+1000) { margin-left: 4rem; }
In an ideal world this would increase the margin of theol
dependent on the number ofli
children in contained so that the margin on the left would only be as wide as it needed to be. – Mumbletypeg