CSS - 是否可以在父代中选择多个不同的子元素而不重复父代? [英] CSS - Is it possible to select multiple different child elements within a parent without repeating the parent?
问题描述
我一直下午在CSS选择器,试图找到一个答案,因为它看起来很简单,但我不能为我的生活找到任何解决方案。
I've been pawing over CSS selectors all afternoon in an attempt to find an answer to this because it seems so simple but I cannot for the life of me find any solution.
给定类似于以下结构的结构:
Given a structure similar to:
<div id="about>
<h1></h1>
<h2></h2>
<h3></h3>
</div>
我想使用一个选择器使所有的标题都是不同的字体。
I want to make all of the headers a different typeface specific to this division using one selector.
我的选择器通常是:
#about h1,
#about h2,
#about h3 {
}
现在看起来效率低下以整理ID?
Which now really appears to be inefficient. Is there a way to collate the ID?
#about h1 + h2 + h3 (incorrect)
是否有类似的东西:
#about (h1,h2,h3)
我觉得这应该是显而易见的,一个选择。
I feel as if this should be obvious but I have never seen such a selection.
推荐答案
在纯CSS中是不可能的。
In plain CSS it's not possible. If you set a class on the header tags you can target them with a single selector.
使用类似少,您可以:
#about {
h1, h2, h3 { ... }
}
这篇关于CSS - 是否可以在父代中选择多个不同的子元素而不重复父代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!