CSS 基于父级的多选

标签 css css-selectors

对于以下代码:

<div id="main">
   <div class="one"></div>
   <div class="two"></div>
   <div class="three"></div>
</div>

我想按类名和父级选择里面的所有 3 个 div,如下所示:

div#main div.one div.two div.three{/*apply common properties for all 3*/}

^ 不起作用。

这是一个抽象示例,因此我需要一个与上面类似的解决方案,例如:

div#main>div{/*apply common properties for all 3*/}

在实际情况下不起作用。

谢谢。

最佳答案

我认为除了这个语法之外你没有其他选择:

div#main div.one,
div#main div.two,
div#main div.three
{/*apply common properties for all 3*/}

关于CSS 基于父级的多选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3736750/

相关文章:

css-selectors - <template> + querySelector 使用 :scope pseudo class works with document but not documentFragment

html - 带遍历的相邻选择器

html - 左对齐徽章

javascript - 表单提交后 AJAX onchange 行为发生变化

jquery - 防止外部链接指示器图形显示在图像上

html - CSS child/nth child/typeof 选择器

css - html和*在为整个页面设置颜色或字体时的区别

css - :not(:last-of-type) not working for class

html - 将 Canvas 的高度和宽度设置为其包含的 div 的高度和宽度

Javascript:从外部 css 文件中删除媒体查询