gpt4 book ai didi

html - 页脚不会到达底部

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

我的页面分为 3 个部分。 header mainfooter

header 固定在顶部并且是 109px 及其 6px 边框高度,所以 main109px 顶部边距。

我希望 main 延伸到页眉下方的整个页面并延伸到页脚,如果没有可用于将其向下推的内容,则应位于屏幕底部。

footer 的高度为 86px,因为顶部的边框为 80px6pxfooter 到底部,main 延伸,但如果页面比页面长,则 footer 不会被向下推。

如果 main 的内容增加了,如何让 footer 保持在底部?

html {
height: 100%;
box-sizing: border-box;
}

body {
background-color: #f5f5f5;
margin: 0;
padding: 0;
position: relative;
height: 100%;
}


/* ---------------------------------------------------------------- */

main {
padding-top: 120px;
/* eigendlich 109px */
padding-bottom: 150px;
/* eigendlich 86px */
text-align: center;
}

#all {
height: 100%;
}

#header {
background-color: #25211e;
border-bottom: 6px solid #1d1a18;
text-align: center;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 103px;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
z-index: 99;
}

#heading {
font-family: "titlefont";
color: #c1b497;
font-size: 45px;
display: inline-block;
margin-bottom: 10px;
margin-top: 15px;
}

#footer {
background-color: #25211e;
border-top: 6px solid #1d1a18;
text-align: center;
position: absolute;
right: 0;
bottom: 0;
left: 0;
height: 80px;
z-index: 98;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
}

#credit {
font-family: "Helvetica";
font-size: 14px;
color: #c1b497;
font-weight: 600;
}
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Page</title>
<script src="script.js"></script>
</head>

<body>
<div id="all">
<header id="header">
<h1 id="heading">My Page</h1>
</header>
<main id="main">
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
</main>
<footer id="footer">
<p id="credit">FOOTER</p>
</footer>
</div>
</body>

</html>

最佳答案

你可以改变

 position: fixed;

在你的 #footer CSS 中

html {
height: 100%;
box-sizing: border-box;
}

body {
background-color: #f5f5f5;
margin: 0;
padding: 0;
position: relative;
height: 100%;
}


/* ---------------------------------------------------------------- */



#all {
height: 100%;
}

#header {
background-color: #25211e;
border-bottom: 6px solid #1d1a18;
text-align: center;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 103px;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
z-index: 99;
}

#heading {
font-family: "titlefont";
color: #c1b497;
font-size: 45px;
display: inline-block;
margin-bottom: 10px;
margin-top: 15px;
}
main {
padding-top: 120px;
/* eigendlich 109px */
padding-bottom: 150px;
/* eigendlich 86px */
text-align: center;
}
#footer {
background-color: #25211e;
border-top: 6px solid #1d1a18;
text-align: center;
position: fixed;
right: 0;
bottom: 0;
left: 0;
height: 80px;
z-index: 98;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
}

#credit {
font-family: "Helvetica";
font-size: 14px;
color: #c1b497;
font-weight: 600;
}
  <div id="all">
<header id="header">
<h1 id="heading">My Page</h1>
</header>
<main id="main">
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
<h2>Content</h2>
</main>
<footer id="footer">
<p id="credit">FOOTER</p>
</footer>
</div>

关于html - 页脚不会到达底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43685888/

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