是否有一种方法可以为同一个父级的nth-child CSS规则分组 [英] Is there a way to group nth-child CSS rules for same parent

查看:338
本文介绍了是否有一种方法可以为同一个父级的nth-child CSS规则分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下CSS规则:

 #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?

由于代码结构是由第三方代码创建的,我不能添加一个不同的类或更改HTML结构。

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

我找不到一个CSS方法,允许选择一个具有多个不同子元素的父元素,而不重写子元素的整个路径。
此外,我没有额外的CSS预处理器可用。

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.

推荐答案

您当前的CSS规则是最短的, 可用。

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

这篇关于是否有一种方法可以为同一个父级的nth-child CSS规则分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆