【发布时间】:2020-01-02 18:20:53
【问题描述】:
我正在尝试扩大 div 的宽度,这样做时我还希望其宽度左侧的 div 缩小到宽度 0px 并消失。
这就是我的got to
我无法缩小第一个(左)div 的宽度。我还需要第三个 div(右)永远不会改变大小,不受动画的影响。
html
<div id='container'>
<div id='one'>one</div>
<div id='two'>two</div>
<div id='three'>three</div>
</div>
css
#container {
position: relative;
border-style: dotted;
height: 100px;
width: 318px;
}
#one {
border-style: dotted;
border-color: red;
left: 0;
width: 200px;
height: 100px;
min-width: 0px;
position: absolute;
}
#two {
border-style: dotted;
border-color: cadetblue;
width: 0px;
height: 100px;
max-width: 200px;
position: absolute;
top: 0;
right: 100px;
animation: enter-right 20s linear infinite;
}
#three {
border-style: dotted;
border-color: goldenrod;
width: 100px;
right: 0;
min-width: 100px;
height: 100px;
position: absolute;
}
@keyframes enter-right {
0% {
transform: translateX(0);
}
10%,
90% {
transform: translateX(0);
}
98%,
100% {
width: 100%;
}
}
【问题讨论】:
-
你的盒子有
absolute的位置有什么特别的原因吗?
标签: javascript html css reactjs css-animations