首页 > 解决方案 > CSS在一个类中选择一个类中的所有元素

问题描述

我正在使用 CMS(Joomla),它们允许我为标签放置一个类,然后我可以修改该特定页面的 css。

我正在尝试使用MDN来找到答案,但我无法完全按照我想要的方式工作。

这是他们页面上的 JSFiddle,我在搞乱它: https ://jsfiddle.net/amvz5dkb/13/

<div class="divclass">
  <span class="spanclass">Span #1, in the div.
    <span="betterspanclass">Span #2, in the span that's in the div.</span>
        <span="betterspanclass">Span #3, in the span 1.</span>
  </span>
</div>
<span>Span #4, not in the div at all.</span>

这是我的 CSS

.divclass >  .betterspanclass {
  background-color: red;
}

这个不行,只能

.divclass > span {
  background-color: red;
}

似乎有效果,但它根本不影响跨度3,只影响跨度1和跨度2。我想为divclass中的每个betterspanclass设置背景红色。这可能吗?

标签: css

解决方案


推荐阅读