html - 如何修复 div 在 html 中不能正确收缩
问题描述
我在一个 flexbox 中有 3 个 div,当光标悬停在其中一个上时,一个展开,另外两个缩小。当我将光标悬停在一个上时,它会扩展,但其他的不会正确缩小(如果我将鼠标悬停在第一个上,它们都会这样做,但当我将鼠标悬停在第二个或第三个上时不会)
body {
display: flex;
flex-direction: row;
}
div {
width: 250px;
height: 100px;
background-color: black;
margin: 10px;
transition: width 0.1s ease-in-out;
}
.e1:hover { width: 500px; }
.e1:hover ~ .e2 { width: 100px; }
.e1:hover ~ .e3 { width: 100px; }
.e2:hover { width: 500px; }
.e2:hover ~ .e1 { width: 100px; }
.e2:hover ~ .e3 { width: 100px; }
.e3:hover { width: 500px; }
.e3:hover ~ .e1 { width: 100px; }
.e3:hover ~ .e2 { width: 100px; }
<body>
<div class="e3">
<p> </p>
</div>
<div class="e2">
<p> </p>
</div>
<div class="e3">
<p> </p>
</div>
</body>
解决方案
最终结果:但它在 CSS 中有限制
.wrapper {
display: flex;
flex-direction: row;
}
.e {
width: 250px;
height: 100px;
background-color: black;
margin: 10px;
transition: transform .2s
}
.wrapper:hover > .e {
transform: scale(0.9)
}
.wrapper:hover .e:hover {
transform: scale(1.1)
}
<div class="wrapper">
<div class="e">
<p> </p>
</div>
<div class="e">
<p> </p>
</div>
<div class="e">
<p> </p>
</div>
</div>
推荐阅读
- python - Flask-Mqtt的Python Flask工厂应用程序问题没有属性'init_app'
- c# - 在 MVVM 中使用 DelegateCommand 的异步 CanExecute 方法
- python - 提取部分 json 键值并组合
- java - 如何分隔 JFrame 中的面板以分隔类
- c# - 防止来自用户的并发控制器请求
- c++ - 双链表不读取整个txt文件
- c# - C# Firebase 从数据库中获取时间戳
- javascript - 如何在反应中创建折叠展开列表
- javascript - 如何使用下拉选项隐藏和显示按钮?
- javascript - 我想访问 javascript 函数中的输入字段,其 id 是使用 php 代码生成的