我想用CSS将身体的大小固定在页面首次加载时的初始尺寸
我想将车身的大小固定到初始尺寸(首先加载页面时大小以防止在动画大小的元素中对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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果要在初始负载上修复尺寸,这是纯JavaScript解决方案:
因此,执行Intial Domcontentloaded事件后进行操作,然后修复身体高度。
This is pure javascript solution if you want to fix size on initial load:
So, you do it after intial DOMContentLoaded event is executed and then fix body height.
您应该查看:
fit-content
,max-content
,min-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 usemax-height: fit-content
and/ormin-height: fit-content
.