我想用CSS将身体的大小固定在页面首次加载时的初始尺寸

发布于 2025-02-03 02:38:42 字数 671 浏览 4 评论 0原文

我想将车身的大小固定到初始尺寸(首先加载页面时大小以防止在动画大小的元素中对IT进行任何更改)。

我该怎么做?

body {
  height: initial; /* This does not work */
}

也不

body {
   height: 200vh;
}

而且这个编辑 这是动画


.small-logo img {  /* This class is toggled in JS*/
    height: 40px;
    /* animation: name duration timing-function delay iteration-count direction fill-mode; */
    animation: shrink 1s ease;
    animation-iteration-count: 1;
}

@keyframes shrink {
    0% {
        height: 100px;
        top: -100px;
        opacity: 10%;
    }
    100% {
        height: 40px;
        top: 0px;
        opacity: 100%;
    }
}

I want to fix the size of the body to the initial size (size when the page first loaded to prevent any changes to the it from elements that resize on animations).

How do i do this?

body {
  height: initial; /* This does not work */
}

and neither does this

body {
   height: 200vh;
}

EDIT -
This is the animation


.small-logo img {  /* This class is toggled in JS*/
    height: 40px;
    /* animation: name duration timing-function delay iteration-count direction fill-mode; */
    animation: shrink 1s ease;
    animation-iteration-count: 1;
}

@keyframes shrink {
    0% {
        height: 100px;
        top: -100px;
        opacity: 10%;
    }
    100% {
        height: 40px;
        top: 0px;
        opacity: 100%;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如梦亦如幻 2025-02-10 02:38:42

如果要在初始负载上修复尺寸,这是纯JavaScript解决方案:

document.addEventListener('DOMContentLoaded', function () {
  // find out your body's height and hardcode it programmaticaly:
  var height = document.getElementsByTagName('body')[0].clientHeight;
  document.getElementsByTagName('body')[0].style.height = height +"px"; 
}, false);

因此,执行Intial Domcontentloaded事件后进行操作,然后修复身体高度。

This is pure javascript solution if you want to fix size on initial load:

document.addEventListener('DOMContentLoaded', function () {
  // find out your body's height and hardcode it programmaticaly:
  var height = document.getElementsByTagName('body')[0].clientHeight;
  document.getElementsByTagName('body')[0].style.height = height +"px"; 
}, false);

So, you do it after intial DOMContentLoaded event is executed and then fix body height.

野却迷人 2025-02-10 02:38:42

您应该查看:fit-contentmax-contentmin-content

fit-content将元素的高度设置为所需的空间。为了“保护”高度,您可以使用Max-Height:Fit-Content和/或min-height:fit-content

You should take a look at: fit-content, max-content, min-content.

fit-content sets the height of the element to its needed space. In order to "protect" the height you can use max-height: fit-content and/or min-height: fit-content.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文