我想完成的事情相当简单,但对我来说很复杂。我想徘徊在1个孩子上,而另外2个孩子则改变背景颜色。并为所有3个孩子做同样的事情。如何在悬停1个孩子时更改2个孩子的内容?
HTML代码:
<div class="servhold">
<div class="serv">
<h1>Clean</h1>
<p>test test test test test test test
test test test test test test test
test test test test test test test
</p>
</div>
<div class="serv">
<h1>Creative</h1>
<p>test test test test test test test
test test test test test test test
test test test test test test test
</p>
</div>
<div class="serv">
<h1>Responsive</h1>
<p>test test test test test test test
test test test test test test test
test test test test test test test
</p>
</div>
</div>
CSS代码(我想):
.servhold .serv:hover:nth-child(1) + .serv:nth-child(n+2){
background-color: pink;
}
// hover 1 change background 2+3
.servhold .serv:hover:nth-child(2) + .serv:nth-child(1) , .serv:nth-child(3){
background-color: pink;
}
// hover 2 change background 1+3
.servhold .serv:hover:nth-child(3) + .serv:nth-child(1) , .serv:nth-child(2){
background-color: pink;
}
// hover 3 change background 1+2
任何帮助,将不胜感激(Javascript或jQuery是没关系。)
谢谢。
你的意思是,虽然'创意'在浩ver,'clean'和'responsive'会得到不同的背景吗? –
是的,有点像。 – Graphicoding