gpt4 book ai didi

使用粘性页脚时 CSS 旁侧高度 100%

转载 作者:行者123 更新时间:2023-12-02 11:39:21 25 4
gpt4 key购买 nike

我有一个带有标题和 sticky footer 的布局。两者都是 40px 高。现在我需要添加一个滚动条,它将填充可用空间(垂直)。它应该看起来像这样:

preview

有两个限制:

  • 没有 JavaScript
  • 没有 CSS3 calc() 函数

这个问题有严格的CSS解决方案吗?

最佳答案

这是我要解释的一个小演示:little link .

首先,分别使用绝对固定定位页眉页脚。在 body 的顶部和底部添加 40px 的内边距,并确保其 box-sizingborder-box >。将 asideheight 设置为 100%,并确保它是一个 border-box。基本上;

HTML:

<header>
I'm a header!
</header>
<aside>
Lots and lots and lots of content!
Glee is awesome!
</aside>
<footer>
I'm a footer!
</footer>

CSS:

html {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
height: 100%;
}
body {
padding-top: 40px;
padding-bottom: 40px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
height: 100%;
}
header {
height: 40px;
width: 100%;
position: absolute;
top: 0px;
}
footer {
height: 40px;
width: 100%;
position: fixed;
bottom: 0px;
}
aside {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
height: 100%;
overflow: auto; /*make sure there are scrollbars when needed*/
}

关于使用粘性页脚时 CSS 旁侧高度 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12328681/

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