我不知道如何解释这个很好但是... 我想选择一个元素,但它与其他元素“相距甚远”
像这样:
<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/