gpt4 book ai didi

html - 页眉、主要和页脚定位

转载 作者:行者123 更新时间:2023-11-28 03:52:31 29 4
gpt4 key购买 nike

我的页面分为 3 个部分。 页眉 主要页脚header 固定在顶部,大小为 109px,边框高 6px,因此 ma​​in 到顶部的边距为 109px。我希望 ma​​in 扩展到 header 下方的整个页面并扩展到 footer 如果没有可用于推送它的内容下来,停留在屏幕的底部。 页脚 的高度为 86 像素,因为顶部的边框为 80 像素和 6 像素。我怎样才能实现这一切。我不知道

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

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


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

main {
margin-top: 109px;
text-align: center;
min-height: 100%;
min-width: 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: 0px 0px 14px 2px rgba(0, 0, 0, 0.75);
z-index: 99;
}

#heading {
font-family: "Arial";
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;
}

#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">



</main>
<footer id="footer">
<p id="credit">FOOTER</p>
</footer>
</div>

最佳答案

您只需要从 body 中删除 padding-bottom 并将 margin-top 替换为 padding-top & 填充底部:

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

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

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

main {
padding-top: 109px;
padding-bottom: 86px;
text-align: center;
}

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

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

#navigation {
margin: 0px;
margin-bottom: 20px;
padding: 0px;
}

.navigationlink {
font-family: "Helvetica";
text-decoration: none;
font-weight: 800;
color: #ffffff;
font-size: 11px;
height: 52px;
letter-spacing: 1px;
margin: 0 10px;
padding-left: 0px;
padding-right: 0px;
position: relative;
text-transform: uppercase;
transition: color 0.3s;
}

.navigationlink:hover {
color: #c1b497;
}

.activelink:hover {
border-bottom-color: #c1b497;
}

.activelink {
border-bottom: 2px solid #ffffff;
transition: color 0.3s;
}

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

#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;
}

#credit {
font-family: "Helvetica";
font-size: 14px;
color: #c1b497;
font-weight: 600;
}
<div id="all">
<header id="header">
<h1 id="heading">My Page</h1>
<nav id="navigation">
<a class="navigationlink activelink" href="index.html">Home</a>
<a class="navigationlink" href="page1.html">Page1</a>
<a class="navigationlink" href="page2.html">Page2</a>
<a class="navigationlink" href="page3.html">Page3</a>
<a class="navigationlink" href="page4.html">Page4</a>
</nav>
</header>
<main id="main"></main>
<footer id="footer">
<p id="credit">FOOTER</p>
</footer>
</div>

关于html - 页眉、主要和页脚定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43656240/

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