gpt4 book ai didi

css - 3行布局,中间展开,最小高度:100% so footer is at bottom when there is minimal content

转载 作者:行者123 更新时间:2023-12-02 05:13:51 24 4
gpt4 key购买 nike

我该如何更改它以使中间的 div 垂直扩展以填充空白区域?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">

body,td,th {
font-family: Tahoma, Geneva, Verdana, sans-serif;
}

html,body {
margin:0;
padding:0;
height:100%; /* needed for container min-height */
}

#container {
position:relative; /* needed for footer positioning*/
margin:0 auto; /* center, not in IE5 */
width:100%;

height:auto !important; /* real browsers */
height:100%; /* IE6: treaded as min-height*/

min-height:100%; /* real browsers */
}

#header {
height: 150px;
border-bottom: 2px solid #ff8800;
position: relative;
background-color: #c97c3e;
}

#middle {
padding-right: 90px;
padding-left: 90px;
padding-top: 35px;
padding-bottom: 43px;
background-color: #0F9;
}
#footer {
border-top: 2px solid #ff8800;
background-color: #ffd376;
position:absolute;
width:100%;
bottom:0; /* stick to bottom */
}
</style>
</head>

<body>

<div id="container">
<div id="header">
Header
</div>
<div id="middle">
Middle
</div>
<div id="footer">
Footer
</div>
</div>

</body>
</html>

最佳答案

如果没有 Javascript,您无法让实际的 div 展开以填充空白,但您可以轻松地让它看起来像这样做。移动你的规则 background-color:#0F9;从#middle 到#container。这将为您提供所需的行为(当内容最少时它会填补空白,当内容很多时它会向下扩展并插入页脚)。

但是,如果您需要 Javascript 解决方案,则可以使用以下代码。只需将其放入您的 HTML head 部分:

<script type="text/javascript">
window.onload = function() {
var mid = document.getElementById('middle');
var foot = document.getElementById('footer');
mid.style.height = ((foot.offsetTop+foot.clientHeight)-(mid.offsetTop+mid.clientHeight))+'px';
};
</script>

关于css - 3行布局,中间展开,最小高度:100% so footer is at bottom when there is minimal content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2839582/

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