我不知道如何很好地解释这一点,但是...
我想选择一个元素,但它与其他元素很像
像这样:
<div class="image-div">
<img src="forest.png" class="image forest">
</div>
<p>
I want to change the color of this text if the image there ^ is "forest", which I'll change with JS
</p>
.image.forest [some selector idk] p {
color: red;
}
.image.train [some selector idk] p {
color: blue;
}
最佳答案
如果它适合您,您可以像这样重写它。
<div class="image-div forest">
<img src="forest.png" class="image">
</div>
<p>I want to change the color of this text if the image there ^ is "forest", which I'll change with JS</p>
<style>
.forest + p {
color: red;
}
.train + p {
color: blue;
}
</style>
关于html - CSS-选择下一个元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40142681/