gpt4 book ai didi

html - 为什么高度 100% 对内容不起作用?

转载 作者:行者123 更新时间:2023-11-28 07:50:51 24 4
gpt4 key购买 nike

在这段代码中,我有一个粘性页脚和上面的内容部分,但为什么 height:100% 对内容部分不起作用?

html {
position: relative;
min-height: 100%;
}
body {
margin-bottom: 60px;
height: 100%;
}
.content {
background-color: #116655;
height: 100%;
}
.footer {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 60px;
background-color: #ffcc44;
}
<div class="content">
<div>content</div>
</div>

<footer class="footer">
My footer
</footer>

最佳答案

您需要在 html

上设置实际高度
html {
position: relative;
height: 100%; /* not min-height */
}

JsFiddle Demo

关于html - 为什么高度 100% 对内容不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30428477/

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