粘性页脚覆盖主体内容

Sticky Footer covers main Body Content

我正在尝试制作一个带有粘性页脚的网页,但是当正文内容足够长时,页脚会与内容重叠。你能告诉我如何解决这个问题吗?我已经尝试了大约 5 种不同的 "sticky footer" 脚本,但每一种都不起作用。

谢谢!

https://jsfiddle.net/za9jzdf6/

html {
    position: relative;
    min-height: 100%; 
   
   
}
body {
 margin: 0 0 170px; /* bottom = footer height */
 background-color: #FFFFFF;
 min-height: 100%; 
}


footer {
 
 padding-top: 20px;
 padding-bottom: 0px;
 background-color: #5D9CFF;
    position: absolute;
    left: 0;
    bottom: 0;
    height: 170px;
    width: 100%;
 text-align: center;
 background-color: #4a80b0;
 background-image: url("http://www.transparenttextures.com/patterns/navy.png");

}


header {
 position: relative;
 background-image:url(http://s6.postimg.org/3osi1wfld/starmenu.png);
 
    margin: 0 auto;

 height: 299px;;
 width: 893px;
 
 z-index:: 1000;
 
}



menu {
 
 position: relative;
 top: 40px;
    
 }


#contentbg {
 
 height: 100%;
    background-color: #F3F3F3;
 margin: 0 auto;
 min-height: 100%; 
 text-align: center;
    
 }




#paypal {
 
 text-align: center; 
 margin: 0 auto; 
 
 }



#contentmain{
 
 margin: 0 auto;
 text-align: center;
 min-height: 100%; 
 
 }



#headerwrap {
 
 margin: 0 auto;
 
 height: 254px;
 
 background-color: #bd4617;
 background-image: url("http://www.transparenttextures.com/patterns/dark-stripes-light.png");
 
}




.nl {
    text-decoration:none;
}

h2 {
 color: #055DBB;
 font-style: italic;
 font-weight: 400;
 letter-spacing: -1px;
 line-height: 1.1em;
 text-align: center;
 font-size: 30px;
 font-family: "Myriad Web Pro", Palatino, "Palatino Linotype", "Times New Roman", "Times Italic";
} 




h3 {
 color: #232323;
 font-style: normal;
 font-weight: 400;
 letter-spacing: -1px;
 line-height: 1.1em;
 text-align: center;
 font-size: 22px;
 font-family: "Myriad Web Pro", Palatino, "Palatino Linotype", "Times New Roman", "Times Italic";
} 


h4 {
  font
  color:#FFFFFF;
 text-align: center;
 font-size: 16px;
 font-family: Calibri;
 color: #FFFFFF;
 font-weight: 300;
 font-style: normal;
 font-variant: small-caps;
} 


h10 {
  text-align: center;
 color: #055DBB;
 font-style: normal;
 font-weight: 400;
 letter-spacing: -1px;
 line-height: 1.1em;
 text-align: center;
 font-size: 30px;
 font-family: "Myriad Web Pro", Palatino, "Palatino Linotype", "Times New Roman", "Times Italic";
} 




h12 {
 text-align: center;
 color: #000000;
 font-style: normal;
 font-size: 20px;
 font-family: "Myriad Web Pro", Palatino, "Palatino Linotype", "Times New Roman", "Times Italic";
 font-weight: bold;
} 


h13 {
 text-align: center;
 color: #000000;
 font-style: normal;
 font-size: 20px;
 font-family: "Myriad Web Pro", Palatino, "Palatino Linotype", "Times New Roman", "Times Italic";
 font-weight: normal;
 
 
 } 

h14 {
 text-align: center;
 color: #006CFF;
 font-style: normal;
 font-size: 20px;
 font-family: "Myriad Web Pro", Palatino, "Palatino Linotype", "Times New Roman", "Times Italic";
 font-weight: bold;
 
 } 



a.header:link {
 color: #000000;
 font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
 font-size: 22px;
 text-decoration: none;
 font-style: normal;
 font-weight: bold;
 font-variant: small-caps;
}

a.header:visited {
  color: #000000;
   font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
 font-size: 22px;
 text-decoration: none;
 font-style: normal;
 font-weight: bold;
 font-variant: small-caps;
}

a.header:hover {
 color: #0069CC;
  font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
 font-size: 22px;
 text-decoration: none;
 font-style: normal;
 font-weight: bold;
 font-variant: small-caps;
}

a.header:active {
 
  color: #000000;
   font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
 font-size: 22px;
 text-decoration: none;
 font-style: normal;
 font-weight: bold;
 font-variant: small-caps;
}

#menu {
  margin-left: 33px;
  position: absolute;
  top: 165px;
}

.row a {
  margin: 0 20px 0 4px;
}

.row a:nth-child(3) {
  margin-left: 310px;
}




.row a:nth-child(2) {
  margin-left: 12px;
}

.row a:nth-child(1) {
  margin-left: 20px;
}
<body>


<div id = "headerwrap">




<header>

<div class="row" id="menu">

<a href="latestindexv1.html" class="header">Home</a>

<a href="coinmarket.html" class="header">Coin Market</a>

<a href="autobuyer.html" class="header">Autobuyer</a> 

<a href="contact.html" class="header">Contact </a>

</div>

</header>


  

</headerwrap>




<div id = "contentmain">


<br><br>

<br><br>



<h13>
  <p>text</p>
  <p>text</p>
  <p>text</p>
</h13>



<div id="form">

<iframe src="https://docs.google.com/forms/d/1aEWswORyYcfzLGW6sCEYN3IKY75rXoxYG7750ikMbjI/viewform?embedded=true" width="560" height="950" frameborder="0" marginheight="0" marginwidth="0">Loading...</iframe>


</div>

    
</div>




<footer>
  
  
  
  &nbsp;&nbsp;&nbsp;
  <a href="http://www.skype.com" class="nl" target="blank" title="skype">
  <img src="images/footer_icons/skype_off.png" width="40" height="40" onmouseover="this.src='images/footer_icons/skype_on.png'" onmouseout="this.src='images/footer_icons/skype_off.png'" border="0" />
  </a>
  
  &nbsp;&nbsp;&nbsp;
  <a href="http://www.skype.com" class="nl" target="blank" title="youtube">
  <img src="images/footer_icons/youtube_off.png" width="40" height="40" onmouseover="this.src='images/footer_icons/youtube_on.png'" onmouseout="this.src='images/footer_icons/youtube_off.png'" border="0" />
  </a>
  
  &nbsp;&nbsp;&nbsp;
  
 <a href="WEBSITE URL HERE" class="nl" target="blank" title="email">
  <img src="images/footer_icons/mail_off.png" width="40" height="40" onmouseover="this.src='images/footer_icons/mail_on.png'" onmouseout="this.src='images/footer_icons/mail_off.png'" border="0" />
  </a>
  
  &nbsp;&nbsp;&nbsp;
  
   <a href="WEBSITE URL HERE" class="nl" target="blank" title="viber">
  <img src="images/footer_icons/viber_off.png" width="40" height="40" onmouseover="this.src='images/footer_icons/viber_on.png'" onmouseout="this.src='images/footer_icons/viber_off.png'" border="0" />
  </a>
  
  &nbsp;&nbsp;&nbsp;
  
  <h4>All copyrights belong to their respective owners.
<br><br>
2015&nbsp;&nbsp;&nbsp;&#9917;&nbsp;&nbsp;&nbsp;SamArt Studio</h4>



</footer>


</body>

在您的示例中,您必须在 HTML 中将 </headerwrap> 更改为 </div>,并在 CSS 中将 footer 更改为 position: fixed; .

将您的位置更改为相对,我在内容和页脚之间的内容之间添加了额外的 div - 'push' div Output

html {
  position: relative;
  min-height: 100%;
}
body {
  margin: 0 0 170px;
  /* bottom = footer height */
  background-color: #FFFFFF;
  min-height: 100%;
}
#push {
  height: 170px;
}
footer {
  padding-top: 20px;
  padding-bottom: 0px;
  background-color: #5D9CFF;
  position: relative;
  left: 0;
  bottom: 0;
  height: 170px;
  width: 100%;
  text-align: center;
  background-color: #4a80b0;
  background-image: url("http://www.transparenttextures.com/patterns/navy.png");
}
header {
  position: relative;
  background-image: url(http://s6.postimg.org/3osi1wfld/starmenu.png);
  margin: 0 auto;
  height: 299px;
  ;
  width: 893px;
  z-index: : 1000;
}
menu {
  position: relative;
  top: 40px;
}
#contentbg {
  height: 100%;
  background-color: #F3F3F3;
  margin: 0 auto;
  min-height: 100%;
  text-align: center;
}
#paypal {
  text-align: center;
  margin: 0 auto;
}
#contentmain {
  margin-top: 0;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: -170px;
  text-align: center;
  min-height: 100%;
  position: relative;
}
#headerwrap {
  margin: 0 auto;
  height: 254px;
  background-color: #bd4617;
  background-image: url("http://www.transparenttextures.com/patterns/dark-stripes-light.png");
}
.nl {
  text-decoration: none;
}
h2 {
  color: #055DBB;
  font-style: italic;
  font-weight: 400;
  letter-spacing: -1px;
  line-height: 1.1em;
  text-align: center;
  font-size: 30px;
  font-family: "Myriad Web Pro", Palatino, "Palatino Linotype", "Times New Roman", "Times Italic";
}
h3 {
  color: #232323;
  font-style: normal;
  font-weight: 400;
  letter-spacing: -1px;
  line-height: 1.1em;
  text-align: center;
  font-size: 22px;
  font-family: "Myriad Web Pro", Palatino, "Palatino Linotype", "Times New Roman", "Times Italic";
}
h4 {
  font color: #FFFFFF;
  text-align: center;
  font-size: 16px;
  font-family: Calibri;
  color: #FFFFFF;
  font-weight: 300;
  font-style: normal;
  font-variant: small-caps;
}
h10 {
  text-align: center;
  color: #055DBB;
  font-style: normal;
  font-weight: 400;
  letter-spacing: -1px;
  line-height: 1.1em;
  text-align: center;
  font-size: 30px;
  font-family: "Myriad Web Pro", Palatino, "Palatino Linotype", "Times New Roman", "Times Italic";
}
h12 {
  text-align: center;
  color: #000000;
  font-style: normal;
  font-size: 20px;
  font-family: "Myriad Web Pro", Palatino, "Palatino Linotype", "Times New Roman", "Times Italic";
  font-weight: bold;
}
h13 {
  text-align: center;
  color: #000000;
  font-style: normal;
  font-size: 20px;
  font-family: "Myriad Web Pro", Palatino, "Palatino Linotype", "Times New Roman", "Times Italic";
  font-weight: normal;
}
h14 {
  text-align: center;
  color: #006CFF;
  font-style: normal;
  font-size: 20px;
  font-family: "Myriad Web Pro", Palatino, "Palatino Linotype", "Times New Roman", "Times Italic";
  font-weight: bold;
}
a.header:link {
  color: #000000;
  font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
  font-size: 22px;
  text-decoration: none;
  font-style: normal;
  font-weight: bold;
  font-variant: small-caps;
}
a.header:visited {
  color: #000000;
  font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
  font-size: 22px;
  text-decoration: none;
  font-style: normal;
  font-weight: bold;
  font-variant: small-caps;
}
a.header:hover {
  color: #0069CC;
  font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
  font-size: 22px;
  text-decoration: none;
  font-style: normal;
  font-weight: bold;
  font-variant: small-caps;
}
a.header:active {
  color: #000000;
  font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
  font-size: 22px;
  text-decoration: none;
  font-style: normal;
  font-weight: bold;
  font-variant: small-caps;
}
#menu {
  margin-left: 33px;
  position: relative;
  top: 165px;
}
.row a {
  margin: 0 20px 0 4px;
}
.row a:nth-child(3) {
  margin-left: 310px;
}
.row a:nth-child(2) {
  margin-left: 12px;
}
.row a:nth-child(1) {
  margin-left: 20px;
}
<body>
  <div id="headerwrap">
    <header>
      <div class="row" id="menu">
        <a href="latestindexv1.html" class="header">Home</a>

        <a href="coinmarket.html" class="header">Coin Market</a>

        <a href="autobuyer.html" class="header">Autobuyer</a> 
        <a href="contact.html" class="header">Contact </a>

      </div>
    </header>
    </headerwrap>
    <div id="contentmain">
      <br>
      <br>
      <br>
      <br>
      <h13>
        <p>text</p>
        <p>text</p>
        <p>text</p>
      </h13>
      <div id="form">
        <iframe src="https://docs.google.com/forms/d/1aEWswORyYcfzLGW6sCEYN3IKY75rXoxYG7750ikMbjI/viewform?embedded=true" width="560" height="950" frameborder="0" marginheight="0" marginwidth="0">Loading...</iframe>
      </div>
    </div>
    <div id="push">&nbsp;</div>
    <footer>&nbsp;&nbsp;&nbsp;
      <a href="http://www.skype.com" class="nl" target="blank" title="skype">
        <img src="images/footer_icons/skype_off.png" width="40" height="40" onmouseover="this.src='images/footer_icons/skype_on.png'" onmouseout="this.src='images/footer_icons/skype_off.png'" border="0" />
      </a>
      &nbsp;&nbsp;&nbsp;
      <a href="http://www.skype.com" class="nl" target="blank" title="youtube">
        <img src="images/footer_icons/youtube_off.png" width="40" height="40" onmouseover="this.src='images/footer_icons/youtube_on.png'" onmouseout="this.src='images/footer_icons/youtube_off.png'" border="0" />
      </a>
      &nbsp;&nbsp;&nbsp;
      <a href="WEBSITE URL HERE" class="nl" target="blank" title="email">
        <img src="images/footer_icons/mail_off.png" width="40" height="40" onmouseover="this.src='images/footer_icons/mail_on.png'" onmouseout="this.src='images/footer_icons/mail_off.png'" border="0" />
      </a>
      &nbsp;&nbsp;&nbsp;
      <a href="WEBSITE URL HERE" class="nl" target="blank" title="viber">
        <img src="images/footer_icons/viber_off.png" width="40" height="40" onmouseover="this.src='images/footer_icons/viber_on.png'" onmouseout="this.src='images/footer_icons/viber_off.png'" border="0" />
      </a>
      &nbsp;&nbsp;&nbsp;
      <h4>All copyrights belong to their respective owners.
<br><br>
2015&nbsp;&nbsp;&nbsp;&#9917;&nbsp;&nbsp;&nbsp;SamArt Studio</h4>

    </footer>
</body>