有没有可能使hover
元素不向下推其他元素从而扩展整个flexbox,而是让它与其他元素重叠并将它们隐藏在其主体中?
我尝试了z-index,但没有成功。
.flex-container {
display: flex;
justify-content: space-evenly;
flex: auto;
}
.flex-container>div {
background-color: #f1f1f1;
width: 100%;
margin: 10px;
line-height: 15px;
font-size: 15px;
border-radius: 10px;
overflow: hidden;
position: relative;
}
.child {
display: none;
position: relative;
}
.main:hover+.child {
display: block;
color: red;
background-color: yellow;
z-index: 1;
}
<div class="flex-container">
<div class="wrapper">
<p class="main">
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</p>
<div class="child">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rem, possimus, a! Accusantium temporibus culpa neque ullam libero ipsam, nesciunt id quisquam omnis, possimus error praesentium eum earum dignissimos, quaerat numquam!
</p>
</div>
<p class="main">
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</p>
<div class="child">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rem, possimus, a! Accusantium temporibus culpa neque ullam libero ipsam, nesciunt id quisquam omnis, possimus error praesentium eum earum dignissimos, quaerat numquam!
</p>
</div>
<p class="main">
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</p>
<div class="child">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rem, possimus, a! Accusantium temporibus culpa neque ullam libero ipsam, nesciunt id quisquam omnis, possimus error praesentium eum earum dignissimos, quaerat numquam!
</p>
</div>
</div>
<div class="wrapper"></div>
</div>
1条答案
按热度按时间eni9jsuy1#
在您的示例中,您必须将鼠标悬停在p元素上,子元素将展开或显示,但是当您从p元素释放光标时,子元素将隐藏,因此请尝试以下代码并更改一些代码结构以满足您的要求。