我有四個div,我想在懸停時改變它們的寬度和高度,所以你懸停的那個擴大了,所有其他的縮小了一個擴展的懸停。當我將鼠標懸停在第一個div上時,我設法讓它工作,但是當我嘗試與其他三個相同時,沒有任何反應。 我的HTML:爲什麼通用兄弟組合並不總是工作?
<div id="main">
<div id="mainOne">
<h3>text</h3>
</div>
<div id="mainTwo">
<h3>text2</h3>
</div>
<div id="mainThree">
<h3>text3</h3>
</div>
<div id="mainFour">
<h3>text4</h3>
</div>
</div>
我的CSS:
/* HOVER 1 */
#mainOne:hover{
width:748px;
height:600px;
}
#mainOne:hover + #mainTwo{
width:248px;
height: 600px;
}
#mainOne:hover ~ #mainThree{
height:200px;
}
#mainOne:hover ~ #mainFour{
height:200px;
}
/* END HOVER 1 */
/* HOVER 2 */
#mainTwo:hover{
width:748px;
height:600px;
}
#mainTwo:hover + #mainOne{
width:248px;
height: 600px;
}
#mainTwo:hover + #mainThree{
height:200px;
}
#mainTwo:hover ~ #mainFour{
height:200px;
}
/* END HOVER 2 */
所以,當我將鼠標懸停在銘萬,一切都變了,但是當我將鼠標懸停在mainTwo只是mainTwo變化和弄亂了一切。我究竟做錯了什麼? 謝謝。
我現在明白問題是什麼,我注意到現在Everything縮小了,但是mainOne,因爲它在mainTwo之前,但是看起來這個解決方案對我而言有點太複雜,所以我會花時間理解它。 非常感謝。 – hpdobrica