简体   繁体   English

是否可以在不知道前面的课程的情况下选择共享同一个 Css 课程的孩子?

[英]Is it possible to select children sharing the same Css class, without knowing that class ahead?

Context (skip ahead for question): While designing a Stylish theme for the online typing game, Typeracer (in Css), I stumbled on this problem:上下文(跳过问题):在为在线打字游戏 Typeracer(在 Css 中)设计 Stylish 主题时,我偶然发现了这个问题:

As the user progresses, the portion of the text already typed turns from gray to green.随着用户的进行,已键入的文本部分将从灰色变为绿色。 I would like to change this green color, to any other.我想将这种绿色更改为任何其他颜色。 What the text progress interface looks like on Typeracer Typeracer 上的文本进度界面是什么样的

What makes it difficult, is that this block is broken into multiple spans, without any id, which get assigned multiple random classes -- different ones every game, and which change during the race : Example of the architecture of the text progress interface让它变得困难的是,这个块被分成多个跨度,没有任何 id,它们被分配了多个随机类别——每场比赛不同的类别,并且在比赛期间发生变化文本进度界面的架构示例

Leaving aside the very last span, which is collapsed on the screenshot above, and does not interest us -- a varying number of spans represent the portion of the text which was already typed, and a varying number of others represent the portion which was not typed yet (In the screenshot above, the first two spans contain the "typed" portion, while the last two spans represent the "not typed" portion. But later in the same race, these numbers may become 1 and 2, or 3 and 1, etc.)撇开最后一个跨度,它在上面的屏幕截图中折叠起来,我们不感兴趣 - 不同数量的跨度代表已经输入的文本部分,而不同数量的其他跨度代表未输入的部分尚未输入(在上面的屏幕截图中,前两个跨度包含“已输入”部分,而后两个跨度代表“未输入”部分。但在同一比赛中,这些数字稍后可能变为 1 和 2,或 3 和1 等)

I have however noticed that the spans representing the text already typed, and the spans representing the text which was not typed yet, share the same first class: in the example from screenshot #2, the "typed" portion spans have "vdFKqLpl" as their first class, and the "not typed yet" portion spans have "CARsHknB" as their first class.然而,我注意到代表已经输入的文本的跨度和代表尚未输入的文本的跨度共享相同的第一类:在屏幕截图 #2 的示例中,“输入”部分跨度具有“vdFKqLpl”作为他们的第一堂课,“尚未键入”部分跨度将“CARsHknB”作为第一堂课。

I have attempted to select the first group of spans by their style.color attribute instead:我试图通过它们的 style.color 属性来选择第一组跨度:

.span[style*="color: #99cc00;"] {
    color: #ff0000;
}

But I could not get any results.但我无法得到任何结果。

Question: Is it possible, using css, to select children elements sharing the same first class, without specifically knowing what that class is?问题:是否可以使用 css 选择共享相同第一类的子元素,而无需明确知道该类是什么?

For example, if the parent div is:例如,如果父 div 是:

<div>
    <span unselectable="on" class="vdFKqLpl">When the little bluebird, who has never said a word, starts to sing, </span>
    <span unselectable="on" class="vdFKqLpl CARsHknB">"Spri</span>
    <span unselectable="on" class="CARsHknB WvLvCiod">n</span>
    <span unselectable="on" class="CARsHknB">g</span>
    <span unselectable="on">...</span>
</div>

Where "vdFKqLpl" and "CARsHknB" are randomly attributed classes which I cannot know ahead , is it possible to select the first two divs, which share "vdFKqLpl" as their first class?其中“vdFKqLpl”和“CARsHknB”是我无法提前知道的随机属性类,是否可以选择共享“vdFKqLpl”的前两个div作为它们的第一类?

I don't know if this will work completely, but this could get you closer.我不知道这是否会完全奏效,但这可以让你更接近。

 span { color: green; } span[class*=" "], span[class*=" "] ~ span { color:red; }
 <div> <span unselectable="on" class="vdFKqLpl">When the little bluebird, who has never said a word, starts to sing, </span> <span unselectable="on" class="vdFKqLpl CARsHknB">"Spri</span> <span unselectable="on" class="CARsHknB WvLvCiod">n</span> <span unselectable="on" class="CARsHknB">g</span> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM