gpt4 book ai didi

css - 页脚 div 在另一个 div 下,高度为 :100% and scroll,,带 CSS

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

我有一些 height:100% 的 div,它们包含在这 3 个 div 中:header、main、footer。

(这里你可以看到一个例子:http://i61.tinypic.com/28mjpya.jpg)

在“主要”div 中,我有一个滚动条,我需要它与 height:100%

但是当我对'main' div 执行height:100% 时,我看不到'footer' div。

如果我将使用 position:absulute; 做'footer' div; bottom:0px; 它将隐藏“主”div 的滚动条。

我该如何解决这个问题?


这是我的来源: http://jsfiddle.net/8YEJY/

<div style='position:fixed; left:0px; width:200px; height:100%;'>
<div id='hearer' style='width:100%; height:40px; background-color:lime;'>
aaa
</div>
<div id='main' style='width:100%; height:100%; overflow:scroll; background-color:green;'>
bbb
</div>
<div id='footer' style='width:100%; height:30px; background-color:pink;'>
ccc
</div>
</div>

最佳答案

您可以固定页眉和页脚,让主体滚动,而不是让内容 div 滚动:

HTML:

<div id="header">header</div>

<div id="content">content</div>

<div id="footer">footer</div>

CSS:

html, body { 
margin: 0;
padding: 0;
height: 100%; /* needs to be set */
}

#header, #footer {
width: 100%;
height: 100px; /* needs to be a fixed width! */
position: fixed;
top 0;
background: lightgreen;
}
#footer {
bottom: 0;
}
#content {
width: 100%;
min-height: 100%;
padding-top: 100px;
padding-bottom: 100px;
box-sizing: border-box; /* include the padding in the height */
-moz-box-sizing: border-box;
background: lightblue;
}

还有一个 demo .

[根据您的评论进行编辑]

#content 更改为:

#content {
width: 100%;
position: fixed;
top: 100px;
bottom: 100px;
overflow: auto;
background: lightblue;
}

检查 updated demo .

注意:除了固定定位,您还可以将 #header#content#footer 绝对放置,查看此链接。结果是一样的。

关于css - 页脚 div 在另一个 div 下,高度为 :100% and scroll,,带 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23403794/

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