2017-10-13 46 views
1

对不起,我不太清楚如何阐述问题,所以这个例子可能更好。我该如何定位一类课程的第一个实例

我想针对下列标记的类

<div class="wrapper"> 
    <div class="message bot"></div> <-- HERE 
    <div class="message bot"></div> 
    <div class="message human"></div> <-- HERE 
    <div class="message bot"></div> <-- HERE 
    <div class="message bot"></div> 
    <div class="message human"></div><-- HERE 
    <div class="message human"></div> 
    <div class="message human"></div> 
    <div class="message human"></div> 
    <div class="message bot"></div> <-- HERE 
    <div class="message bot"></div> 
    <div class="message bot"></div> 
</div> 

或者,如果你能提出更好的问题的标题,将是巨大的也是!

作为对this question的重复标记的回应,我会说这是不同的,因为每个项目之间存在随机数量的可能“bot”div或“human”div。

+0

或许,如果有一个轻量级的JS功能,可以选择它,那也可以。 – jackdh

+0

我不怪你。这个问题很难阐明。它之前已经被问过了,但是在[不同的](https://stackoverflow.com/questions/16678857/apply-style-to-first-element-in-a-row-of-similar-elements)和[specific ](https://stackoverflow.com/questions/42588300/repeated-first-occurence-of-an-element)伪装很难涵盖所有的基础。这就是重复提问的原因,更重要的是,这不是一件坏事。只要你链接到合适的副本,当然......作为回答链接问题的人,我同意这不是一个合适的副本。 – BoltClock

回答

3

你可以做这样的事情,但有可能是这种方法的局限性(与继承的样式):

.bot { 
 
    color: red; 
 
} 
 

 
.human { 
 
    color: green; 
 
} 
 

 
.human + .human, 
 
.bot + .bot { 
 
    color: inherit; /* reset necessary style back */ 
 
}
<div class="wrapper"> 
 
    <div class="message bot">bot</div> <!-- HERE --> 
 
    <div class="message bot">bot</div> 
 
    <div class="message human">human</div> <!-- HERE --> 
 
    <div class="message bot">bot</div> <!-- HERE --> 
 
    <div class="message bot">bot</div> 
 
    <div class="message human">human</div> <!-- HERE --> 
 
    <div class="message human">human</div> 
 
    <div class="message human">human</div> 
 
    <div class="message human">human</div> 
 
    <div class="message bot">bot</div> <!-- HERE --> 
 
    <div class="message bot">bot</div> 
 
    <div class="message bot">bot</div> 
 
</div>

+0

什么是加号? –

+0

@Bla ...:https://stackoverflow.com/questions/1139763/what-does-the-plus-sign-css-selector-mean – BoltClock

+0

很好,谢谢! – jackdh

相关问题