gpt4 book ai didi

html - 仅在动画后使用 css 隐藏/删除 div 从 html 占用的空间

转载 作者:太空宇宙 更新时间:2023-11-04 07:32:25 24 4
gpt4 key购买 nike

我正在尝试“物理”删除,或者让 div(例如)在隐藏后不占用屏幕空间。

我在#test div下面又加了一个div,说明#test被隐藏后,还是会占用屏幕空间。有没有办法让那个空间消失,只用 css?

#test {
opacity: 0;
-webkit-animation: fadeinout 3s;
/* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadeinout 3s;
/* Firefox < 16 */
-ms-animation: fadeinout 3s;
/* Internet Explorer */
-o-animation: fadeinout 3s;
/* Opera < 12.1 */
animation: fadeinout 3s;
}

@keyframes fadeinout {
from {
opacity: 0;
}
50% {
opacity: 1;
}
to {
opacity: 0;
}
}

@-moz-keyframes fadeinout {
/* Firefox */
from {
opacity: 0;
}
50% {
opacity: 1;
}
to {
opacity: 0;
}
}

@-webkit-keyframes fadeinout {
/* Safari and Chrome */
from {
opacity: 0;
}
50% {
opacity: 1;
}
to {
opacity: 0;
}
}

@-o-keyframes fadeinout {
/* Opera */
from {
opacity: 0;
}
50% {
opacity: 1;
}
to {
opacity: 0;
}
}
<div id="test">hide me after 3 seconds</div>
<div>After 3 seconds I don't move up.</div>

最佳答案

您还可以设置最大高度的动画 - 只需确保中间的最大高度高于最高的淡化 div

#test {
opacity: 0;
-webkit-animation: fadeinout 3s;
/* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadeinout 3s;
/* Firefox < 16 */
-ms-animation: fadeinout 3s;
/* Internet Explorer */
-o-animation: fadeinout 3s;
/* Opera < 12.1 */
animation: fadeinout 3s;
max-height: 0;
}

@keyframes fadeinout {
from {
max-height: 0;
opacity: 0;
}
50% {
opacity: 1;
max-height: 5em;
}
to {
opacity: 0;
max-height: 0;
}
}
<div id="test">hide me after 3 seconds</div>
<div>After 3 seconds I don't move up.</div>

关于html - 仅在动画后使用 css 隐藏/删除 div 从 html 占用的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49257959/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com