页眉、主要和页脚定位

header, main and footer positioning

我的页面分为 3 个部分。 headermainfooterheader 固定在顶部并且是 109px,其边框高 6px,因此 main 与顶部有 109px 的边距。我希望 main 扩展到 header 下方的整个页面,并扩展到 footer,如果没有可用于下推的内容,则停留在屏幕底部。 footer 高度为 86px,因为顶部边框为 80px 和 6px。我怎样才能实现这一切。我不知道

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>

请把你的问题说清楚,我试试看,这是你想要的吗(固定仓位并去除不必要的边距)?

html {
   height: 100%;
    box-sizing: border-box;
}
body {
    background-color: #f5f5f5;
    margin: 0;
    padding: 0;
    min-height: 100%;
}

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

main {
    text-align: center;
    min-height: 100%;
   min-width: 100%;
}

#header {
 background-color: #25211e;
 border-bottom: 6px solid #1d1a18;
 text-align: center;
  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: fixed;
   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>

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

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>