html - 如何使用绝对位置平滑拉伸 div?
问题描述
我不能平滑地将左上 div 拉伸到 100vh 高度和 100vw 宽度。Box .btn 如我所愿顺利进行,但整个背景(div .red)有某种滞后,最后才顺利进行。请问有什么建议吗?:)
@keyframes stretchIn {
0% {
height: 50vh;
width: 50vw;
z-index: 0;
}
100% {
height: 100vh;
width: 100vw;
z-index: 1;
}
}
body {
background: #999;
margin: 0;
padding: 0;
overflow: hidden;
}
body .red,
body .blue,
body .green,
body .yellow {
position: absolute;
z-index: 0;
height: 50vh;
width: 50vw;
}
body .red {
top: 0;
left: 0;
background: #a04951;
transition: 1s;
}
body .red:hover {
animation: stretchIn 5s both;
}
body .red .btn {
position: relative;
width: 50px;
height: 50px;
background: #fff;
top: 45%;
left: 45%;
}
body .blue {
background: #c06c84;
top: 0;
right: 0;
}
body .green {
bottom: 0;
left: 0;
background: #6c5b7b;
}
body .yellow {
bottom: 0;
right: 0;
background: #355c7d;
}
<div class="red">
<div class="btn"></div>
</div>
<div class="blue"></div>
<div class="green"></div>
<div class="yellow"></div>
解决方案
我从z-index
悬停开始,而不是从动画开始。
@keyframes stretchIn {
to {
height: 100vh;
width: 100vw;
}
}
body {
background: #999;
margin: 0;
padding: 0;
overflow: hidden;
}
.red,
.blue,
.green,
.yellow {
position: absolute;
z-index: 0;
height: 50vh;
width: 50vw;
}
.red {
top: 0;
left: 0;
background: #a04951;
}
.red:hover {
animation: stretchIn 5s both;
z-index: 1;
}
.red .btn {
position: relative;
width: 50px;
height: 50px;
background: #fff;
top: 45%;
left: 45%;
}
.blue {
background: #c06c84;
top: 0;
right: 0;
}
.green {
bottom: 0;
left: 0;
background: #6c5b7b;
}
.yellow {
bottom: 0;
right: 0;
background: #355c7d;
}
<div class="red">
<div class="btn"></div>
</div>
<div class="blue"></div>
<div class="green"></div>
<div class="yellow"></div>
推荐阅读
- amazon-web-services - 通过 AWS CLI 获取 cloudformation 堆栈的 JSON 模板
- javascript - kendodropdownlist 过滤具有字段的 json 响应
- java - 反转字符串 III java 运行时错误中的单词
- python - MDNavigationDrawer 中的按钮在发布时不会更改屏幕
- ios - 使用 SKProductDiscount 的 NumberFormatter (_unconditionallyBridgeFromObjectiveC) 崩溃
- python-3.x - 在 Tkinter 中重复按下按钮时替换 FigureCanvasTkAgg 内容
- sql - MariaDB 中的程序遇到问题
- javascript - Google Drive API:如何列出共享文件夹中的所有文件?
- html - CSS按类选择输入
- python-3.x - 从字符串中去除不需要的字符