粘滞页脚没有完全粘在底部

时间:2016-08-13 06:09:21

标签: html css sticky-footer

我正在尝试在我的双列内容上添加粘性页脚,但问题是它无法完全占据页面底部。

我一直在申请我在网上找到的css粘性页脚,但是我无法让它起作用。

我在下面附上了我的代码。

Codepen代码:I've add my code into Codepen Here

<style> body {
  margin: 0;
  padding: 0;
  /*background-image: url("main-bg.jpg");*/
  background-color:green;
  height: 100%;
}
.container {
  width: 100%;
  position: relative;
  margin-bottom: -50px;
  height: 100%;
}
/* HEADER SECTION */

.header {
  background-color:blue;
  /*background-image: url("bgs.jpg");
  background-repeat: repeat;
  background-size: cover;
  */
  height: 100px;
  overflow: auto;
}
.header ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
}
.header ul li {
  float: right;
  padding: 14px 16px;
}
.header li ul {
  display: none;
}
.header a {
  text-decoration: none;
  color: white;
  font-size: 20px;
}
.header li:hover ul {
  display: block;
}
/*FOOTER SECTION*/

.footer {
  clear: both;
  padding: 5px 5px;
  background: #cc9;
  height: 50px;
}
.footer-right {
  float: right;
}
.footer-left {
  float: left;
}
/*CONTENT SECTION*/

.content {
  padding: 10px;
  padding-bottom: 50px;
  height: 100%;
  overflow: hidden;
  background-color:silver;
  width: 95%;
}
.left-content {
  float: left;
  width: 800px;
  padding: 10px;
  margin-left: 150px;
  margin-right: 20px;
  margin-top: 20px;
  margin-bottom: : 150px;
  /*background-image:url("main-content-bg.png");*/
  background-color: white;
  -webkit-box-shadow: 8px -9px 20px 9px rgba(112, 112, 138, 0.69);
  -moz-box-shadow: 8px -9px 20px 9px rgba(112, 112, 138, 0.69);
  box-shadow: 8px -9px 20px 9px rgba(112, 112, 138, 0.69);
}
.right-content {
  float: right;
  width: 320px;
  padding: 10px;
  background: #99c;
}
#footer {
  clear: both;
  padding: 5px 5px;
  background: #cc9;
  height: 40px;
}
</style>
<body>

  <div class="container">

    <div class="header">
      <br>
      <ul>
        <li><a href="#">HOME</a>
        </li>
        <li><a href="#">SERVICES</a>
        </li>
        <li><a href="#">PORTFOLIO</a>
          <ul>
            <li><a href="#">Birthday Events</a>
            </li>
            <li><a href="#">Wedding Events</a>
            </li>
            <li><a href="#">Anniversary Events</a>
            </li>
            <li><a href="#">Other Events</a>
            </li>
          </ul>
        </li>
        <li><a href="#">CONTACT</a>
        </li>
        <li><a href="#">ABOUT</a>
        </li>
      </ul>
    </div>

    <div class="content">
      <div class="left-content">
        <p>All About Pixel Foto</p>
        <p>Nunc tincidunt, elit non cursus euismod, lacus augue ornare metus, egestas imperdiet nulla nisl quis mauris. Suspendisse a pharetra urna. Morbi dui lectus, pharetra nec elementum eget, vulputate ut nisi. Aliquam accumsan, nulla sed feugiat vehicula,
          lacus justo semper libero, quis porttitor turpis odio sit amet ligula. Duis dapibus fermentum orci, nec malesuada libero vehicula ut. Integer sodales, urna eget interdum eleifend, nulla nibh laoreet nisl, quis dignissim mauris dolor eget mi.
          Donec at mauris enim. Duis nisi tellus, adipiscing a convallis quis, tristique vitae risus. Nullam molestie gravida lobortis. Proin ut nibh quis felis auctor ornare. Cras ultricies, nibh at mollis faucibus, justo eros porttitor mi, quis auctor
          lectus arcu sit amet nunc. Vivamus gravida vehicula arcu, vitae vulputate augue lacinia faucibus. Donec volutpat nibh sit amet libero ornare non laoreet arcu luctus. Donec id arcu quis mauris euismod placerat sit amet ut metus. Sed imperdiet
          fringilla sem eget euismod. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Pellentesque adipiscing, neque ut pulvinar tincidunt, est sem euismod odio, eu ullamcorper turpis nisl sit amet velit.
          Nullam vitae nibh odio, non scelerisque nibh. Vestibulum ut est augue, in varius purus. Quisque ligulas ipsum, euismod atras vulputate iltricies etri elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
          Nulla nunc dui, tristique in semper vel, congue sed ligula. Nam dolor ligula, faucibus id sodales in, auctor fringilla libero. Pellentesque pellentesque tempor tellus eget hendrerit. Morbi id aliquam ligula. Aliquam id dui sem. Proin rhoncus
          consequat nisl, eu ornare mauris tincidunt vitae. Vestibulum sodales ante a purus volutpat euismod. Proin sodales quam nec ante sollicitudin lacinia. Ut egestas bibendum tempor. Morbi non nibh sit amet ligula blandit ullamcorper in nec risus.
          Pellentesque fringilla diam faucibus tortor bibendum vulputate. Etiam turpis urna, rhoncus et mattis ut, dapibus eu nunc. Nunc sed aliquet nisi. Nullam ut magna non lacus adipiscing volutpat. Aenean odio mauris, consectetur quis consequat quis,
          blandit a nunc. Sed orci erat, placerat ac interdum ut, suscipit eu augue. Nunc vitae mi tortor. Ut vel justo quis lectus elementum ullamcorper volutpat vel libero.</p>
      </div>
      <div class="right-content">
        <p align="center">All About Me</p>
        <p>I'm Dick Roman and I foresee what I will become when I first time use a camera. I was eager to have my own camera and take elegant photos of my unforgettable moments in my life. It was served as my inspiration to purse and take this field of photography.
          Today I am able to render my services to my clients and I will guarantee every works I made will be best of the best</p>
        <ol style="list-style-type:none;align:center">
          <p>Today I am rendering my skills as a:</p>
          <li>Image Editor</li>
          <li>Landscape Photograher</li>
          <li>Video Editor</li>
          <li>Web Designer</li>
        </ol>

        <p align="center">You could drop-by to my social media profiles</p>
        <p align="center">Just click on any links below to visit my account</p>

        <ul style="list-style-type:none">
          <li>
            <a href="#">Facebook</a>
          </li>
          <li><a href="#">Twitter</a>
          </li>
          <li><a href="#">Instagram</a>
          </li>
        </ul>
      </div>
    </div>

    <div class="footer">
      <div class="footer-left">
        <p>&copy;Copyright 2016 - Codeblocks Design</p>
      </div>


      <div class="footer-right">
        <p>
          <a href="#">
            <img src="fb.png" height="60%">
          </a>
          <a href="#">
            <img src="twitter.png" height="60%">
          </a>
          <a href="#">
            <img src="instagram.png" height="60%">
          </a>
          <a href="#">
            <img src="google.png" height="60%">
          </a>
        </p>
      </div>
    </div>

  </div>
</body>
上面的代码如何在我的浏览器上显示: Here's the output

2 个答案:

答案 0 :(得分:2)

从您的CSS中删除<style>,它无效selector

对于粘性页脚,使用position:fixed会使其粘在屏幕底部。

以下是已修改 代码段

*{
  margin:0px;
  padding:0px;
}

body {
  margin: 0;
  padding: 0;
  /*background-image: url("main-bg.jpg");*/
  background-color:green;
  height: 100%;
}
.container {
  width: 100%;
  position: relative;
  margin-bottom: -50px;
  height: 100%;
}
/* HEADER SECTION */

.header {
  background-color:blue;
  /*background-image: url("bgs.jpg");
  background-repeat: repeat;
  background-size: cover;
  */
  height: 100px;
  overflow: auto;
}
.header ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
}
.header ul li {
  float: right;
  padding: 14px 16px;
}
.header li ul {
  display: none;
}
.header a {
  text-decoration: none;
  color: white;
  font-size: 20px;
}
.header li:hover ul {
  display: block;
}
/*FOOTER SECTION*/

.footer {
  clear: both;
  padding: 5px 5px;
  background: #cc9;
  height: 50px;
}
.footer-right {
  float: right;
}
.footer-left {
  float: left;
}
/*CONTENT SECTION*/

.content {
  padding: 10px;
  padding-bottom: 50px;
  height: 100%;
  overflow: hidden;
  background-color:silver;
  width: 95%;
}
.left-content {
  float: left;
  width: 800px;
  padding: 10px;
  margin-left: 150px;
  margin-right: 20px;
  margin-top: 20px;
  margin-bottom: : 150px;
  /*background-image:url("main-content-bg.png");*/
  background-color: white;
  -webkit-box-shadow: 8px -9px 20px 9px rgba(112, 112, 138, 0.69);
  -moz-box-shadow: 8px -9px 20px 9px rgba(112, 112, 138, 0.69);
  box-shadow: 8px -9px 20px 9px rgba(112, 112, 138, 0.69);
}
.right-content {
  float: right;
  width: 320px;
  padding: 10px;
  background: #99c;
}
#footer {
  clear: both;
  padding: 5px 5px;
  background: #cc9;
  height: 40px;
}
</style>
<body>

  <div class="container">

    <div class="header">
      <br>
      <ul>
        <li><a href="#">HOME</a>
        </li>
        <li><a href="#">SERVICES</a>
        </li>
        <li><a href="#">PORTFOLIO</a>
          <ul>
            <li><a href="#">Birthday Events</a>
            </li>
            <li><a href="#">Wedding Events</a>
            </li>
            <li><a href="#">Anniversary Events</a>
            </li>
            <li><a href="#">Other Events</a>
            </li>
          </ul>
        </li>
        <li><a href="#">CONTACT</a>
        </li>
        <li><a href="#">ABOUT</a>
        </li>
      </ul>
    </div>

    <div class="content">
      <div class="left-content">
        <p>All About Pixel Foto</p>
        <p>Nunc tincidunt, elit non cursus euismod, lacus augue ornare metus, egestas imperdiet nulla nisl quis mauris. Suspendisse a pharetra urna. Morbi dui lectus, pharetra nec elementum eget, vulputate ut nisi. Aliquam accumsan, nulla sed feugiat vehicula,
          lacus justo semper libero, quis porttitor turpis odio sit amet ligula. Duis dapibus fermentum orci, nec malesuada libero vehicula ut. Integer sodales, urna eget interdum eleifend, nulla nibh laoreet nisl, quis dignissim mauris dolor eget mi.
          Donec at mauris enim. Duis nisi tellus, adipiscing a convallis quis, tristique vitae risus. Nullam molestie gravida lobortis. Proin ut nibh quis felis auctor ornare. Cras ultricies, nibh at mollis faucibus, justo eros porttitor mi, quis auctor
          lectus arcu sit amet nunc. Vivamus gravida vehicula arcu, vitae vulputate augue lacinia faucibus. Donec volutpat nibh sit amet libero ornare non laoreet arcu luctus. Donec id arcu quis mauris euismod placerat sit amet ut metus. Sed imperdiet
          fringilla sem eget euismod. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Pellentesque adipiscing, neque ut pulvinar tincidunt, est sem euismod odio, eu ullamcorper turpis nisl sit amet velit.
          Nullam vitae nibh odio, non scelerisque nibh. Vestibulum ut est augue, in varius purus. Quisque ligulas ipsum, euismod atras vulputate iltricies etri elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
          Nulla nunc dui, tristique in semper vel, congue sed ligula. Nam dolor ligula, faucibus id sodales in, auctor fringilla libero. Pellentesque pellentesque tempor tellus eget hendrerit. Morbi id aliquam ligula. Aliquam id dui sem. Proin rhoncus
          consequat nisl, eu ornare mauris tincidunt vitae. Vestibulum sodales ante a purus volutpat euismod. Proin sodales quam nec ante sollicitudin lacinia. Ut egestas bibendum tempor. Morbi non nibh sit amet ligula blandit ullamcorper in nec risus.
          Pellentesque fringilla diam faucibus tortor bibendum vulputate. Etiam turpis urna, rhoncus et mattis ut, dapibus eu nunc. Nunc sed aliquet nisi. Nullam ut magna non lacus adipiscing volutpat. Aenean odio mauris, consectetur quis consequat quis,
          blandit a nunc. Sed orci erat, placerat ac interdum ut, suscipit eu augue. Nunc vitae mi tortor. Ut vel justo quis lectus elementum ullamcorper volutpat vel libero.</p>
      </div>
      <div class="right-content">
        <p align="center">All About Me</p>
        <p>I'm Dick Roman and I foresee what I will become when I first time use a camera. I was eager to have my own camera and take elegant photos of my unforgettable moments in my life. It was served as my inspiration to purse and take this field of photography.
          Today I am able to render my services to my clients and I will guarantee every works I made will be best of the best</p>
        <ol style="list-style-type:none;align:center">
          <p>Today I am rendering my skills as a:</p>
          <li>Image Editor</li>
          <li>Landscape Photograher</li>
          <li>Video Editor</li>
          <li>Web Designer</li>
        </ol>

        <p align="center">You could drop-by to my social media profiles</p>
        <p align="center">Just click on any links below to visit my account</p>

        <ul style="list-style-type:none">
          <li>
            <a href="#">Facebook</a>
          </li>
          <li><a href="#">Twitter</a>
          </li>
          <li><a href="#">Instagram</a>
          </li>
        </ul>
      </div>
    </div>

    <div class="footer">
      <div class="footer-left">
        <p>&copy;Copyright 2016 - Codeblocks Design</p>
      </div>


      <div class="footer-right">
        <p>
          <a href="#">
            <img src="fb.png" height="60%">
          </a>
          <a href="#">
            <img src="twitter.png" height="60%">
          </a>
          <a href="#">
            <img src="instagram.png" height="60%">
          </a>
          <a href="#">
            <img src="google.png" height="60%">
          </a>
        </p>
      </div>
    </div>

  </div>
</body>

答案 1 :(得分:1)

一种简单的方法是将您的页脚内容放在<footer>标记中。然后应用position:fixed;让页脚粘到底部。

如果之后有任何保证金问题,请将其添加到样式的顶部

*{
    margin:0;
}