1
我想將margin-top
樣式添加到.three
,但前提是.one
有.two
。CSS樣式的子div,但只有父母有以下兄弟
.one {
background: indianred;
height: 100px;
width: 100px;
}
.three {
background: bisque;
height: 100px;
width: 100px;
}
.one .two + .three {
margin-top: 20px;
}
<div class="one">
<div class="two">hello</div>
</div>
<div class="three">there</div>
<div class="one">
</div>
<div class="three">there</div>
可以這樣做?感謝幫助。
單獨使用CSS這是不可能的,但使用JavaScript會很簡單。 – APAD1
CSS無法上父。所以這對於純CSS來說是不可能的。 –
有一天[:has](https://developer.mozilla.org/en-US/docs/Web/CSS/:has)可以:P – Vucko