Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to group nth-child CSS rules for same parent

I have the following CSS rules:

 #div .item62 > .wrap > .cont > .level1 > div:nth-child(9),
 #div .item62 > .wrap > .cont > .level1 > div:nth-child(11),
 #div .item62 > .wrap > .cont > .level1 > div:nth-child(n+12){
    width: 140px ;
 }

I would like to group those rules to make the code shorter and probably to make the code more efficient when the parent element selection would be done once(do those rules make the browser engine search three times the same "parent" element or is this already optimized?).

Is there a way to write these rules in a shorter way?

As the code structure is created by third party code I cannot add a distinct class or change HTML structure.

I could not find a CSS method that would allow to select one parent with multiple distinct child elements without rewriting the whole path to the child elements. Also I have no additional CSS preprocessors avaliable.

like image 345
AndyZ Avatar asked Dec 20 '25 14:12

AndyZ


1 Answers

Your current CSS rule is the shortest you can write without any Preprocessor available.

like image 100
m4n0 Avatar answered Dec 22 '25 08:12

m4n0



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!