I know that with code of the form .class1 + .class2 specified styles are applied to class2 , which immediately follows class1 . But how can I set styles specifically for class1, after which there is class2 ?
|
1 answer
Since there is no reverse selector, like .class1 - .class2 in CSS, some special case can be solved with the selector + or ~ , assigning display: flex parent and setting order descendants. The markup should be based on the assumption that the “previous” element should be located below. An alternative to the order property may be the flex-direction: row-reverse property.
.container { display: flex; } .child { border: 1px solid; padding: 1em; } .class2 { order: 1 } .class3 { order: 2 } .next ~ .prev { background: #ccc; } <div class=container> <div class="child class3">class3</div> <div class="child next class2">class2</div> <div class="child prev class1">class1</div> </div> |
.class1:first-childor.class0 + .class1- webDev_