<分区>
我正在 Squarespace 中创建一个分屏页面,但我在尝试影响同级元素时遇到了问题。当我将鼠标悬停在一侧时,我希望一侧增大而另一侧缩小。我可以让左侧工作,但是当我将鼠标悬停在右侧时,左侧不会缩小。
我试过使用 ~ 并且它有效,但仅适用于一侧。
.Main-content {
padding: 0;
margin: 0;
width: 100vw;
height: 100vh;
overflow-x: hidden;
}
.containerSplit {
position: relative;
width: 100vw;
height: 100vh;
background: #333 !important;
}
.split {
position: absolute;
width: 50vw;
height: 100vh;
overflow: hidden;
}
.split.leftSide {
left: 0;
background-color: red;
background-size: cover;
}
.split.leftSide:hover {
position: absolute;
content: "";
width: 75vw;
height: 100vh;
background-color: red;
z-index: 2;
}
**.split.leftSide:hover~.rightSide,
.split.rightSide:hover~.leftSide {
width: 25vw;
}
** .split.rightSide {
right: 0;
background-color: blue;
background-size: cover;
}
.split.rightSide:hover {
position: absolute;
content: "";
width: 75vw;
height: 100vh;
background-color: blue;
z-index: 2;
}
.split.leftSide,
.split.rightSide,
.split.rightSide:before,
.split.leftSide:before {
transition: 1000ms all ease-in-out;
}
<div class="containerSplit">
<div class="split leftSide">
<h1>The Designer</h1>
<a href="#" class="button">Read More</a>
</div>
<div class="split rightSide">
<h1>The Programmer</h1>
<a href="#" class="button">Read More</a>
</div>
</div>
当我将鼠标悬停在另一个元素上时,我希望同级元素缩小到 25vw。