gpt4 book ai didi

html - 当内容不占据整个页面时的 CSS Sticky Footer

转载 作者:可可西里 更新时间:2023-11-01 13:35:46 26 4
gpt4 key购买 nike

我有两个页面,它们的区别仅在于 content-box div 标记中包含的内容。你可以在这里看到它们:

Tall Version

Short Version

我在下面包含了 short 版本的 html/css 代码。我想要显示short 版本,这样如果内容量没有填满整个页面,页脚仍会贴在底部以及页眉和页脚之间的整个区域屏幕中间是白色,对应于 content-box div。

我需要更改什么才能实现此目的?\

更新 1 我按照@smallworld 的建议创建了一个新页面。可见here .这有一个粘性页脚,但我想要外部“容器”框来扩展页面的高度。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content=
"text/html; charset=us-ascii">
<style type="text/css">


#main {
width: 100%;
min-height: 100%;
height: 100%;
}

body {
width: 100%;
}


#header,#content { position:relative; right:0;left:0}

#header{
height:75px; top:0;
background: #4396CA;
}
#footer{
width: 100%;
position: relative;
height:50px;
bottom: 0;
left: 0;
background: #4396CA;
}
#content{
top:00px;
background: #F0F8FF;
min-height: 100%;
height: 100%;
}

#content-box {
width: 950px;
margin: 0 auto;
background-color: #FFFFFF;
text-align: left;
border-right: 1px solid #B0B0B0;
border-left: 1px solid #B0B0B0;
padding-bottom: 20px;
padding-top: 20px;
min-height: 100%;
height: 100%;
}

</style>
<title>EmbeddedAnalytics - Test Page</title>
</head>
<body>
<div id="main">
<div id="header">this is header</div>
<div id="content">
<div id="content-box">
<b>Content does not take up all of box. But still want footer to "stick" to bottom</b><br>
line1<br>
line2<br>
line3<br>
Last Line<br></div>
</div>
<div id="footer">footer</div>
</div>
</body>
</html>

最佳答案

编辑:参见 http://jsfiddle.net/smallworld/gcpNh/ 上的 jsfiddle - 我在您的示例中使用了 class="xyz"而不是 id="xyz"。我知道拉伸(stretch)到 100% 的高度不应该那么困难和有压力,但实际上确实如此。我感受到你的痛苦,这就是为什么我会尽我所能提供帮助。我又做了一个更正 - 它应该是 padding-bottom,而不是“main”类的 margin-bottom。

CSS:

html {  height:100%;min-height:100% !important;margin:0;padding:0;   /** see height, min-height values here. **/ }
body{ overflow:auto;padding:0;margin:0;height:100%;min-height:100% !important; /** see height, min-height values here. **/ }
.main {
position:relative;min-height:100%; height:auto; background:cyan;
/** see position, height, min-height values here. Height auto to make sure
that main div resizes if window size changes after initial rendering **/
}
.header { display:block;height:50px;position:relative;background:yellow;text-align:center;padding:10px; }
.content { padding:20px;margin-bottom:50px; /** bottom margin here to make sure that footer does not cover the content area **/ }
.footer { display:block;position:absolute;bottom:0;left:0;width:100%;height:50px;background:red;color:white;text-align:center;padding:10px; /** see position, top, left, and width properties here. **/ }

HTML

<div class="main clearfix">
<div class="header">header</div>
<div class="clearfix content">
<h1>Goal of this fiddle is to demonstrate sticky footer implementation</h1>
And domonstrate this with least amount of CSS and HTML, without using any extraordinary hacks.
<p>Your content goes in here. Add lot more content, and resize browser window to several different sizes to see how your page is rendered as compared to with very little content.</p>
</div>
<div class="footer">footer</div>
</div>

关于html - 当内容不占据整个页面时的 CSS Sticky Footer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16827100/

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