html 页脚出现在包装内?

标签 html css css-position footer

我尝试了 clear:both 和 body 的相对位置,但由于某种原因它仍然总是在 wrapper 内显示得更高,我们将不胜感激

这是 jsfiddle 上的代码:

http://jsfiddle.net/38xhn4dz/

这是我正在处理的代码:

<center>
  <img src="images/eshop.jpg" width="800px" height="120px"/>
</center>
<div id="menu">
  <ul class="navigation">
    <li>
      <a href="#" >
        HOME
      </a>
    </li>
    <li>
      <a href="#">
        HOT ITEMS
      </a>
    </li>
    <li>
      <a href="#">
        SELL TO US
      </a>
    </li>
    <li>
      <a href="#">
        ABOUT US
      </a>
    </li>
    <li>
      <a href="#">
        CONTACT
      </a>
    </li>
  </ul>
</div>
<div id="wrap">
  <center>
    <div class="box">
      <h3>
        Neutrogena Body Wash
      </h3>
      <p float="left">
        <img src="images/item1.jpg" width="50%" height="200px" alt="item1"/>
      </p>
      <h4>
        3$
      </h4>
    </div>
    <div class="box">
      <h3>
        Summer Boots
      </h3>
      <p float="left">
        <img src="images/item2.png" width="50%" height="200px" alt="item2"/>
      </p>
      <h4>
        5$
      </h4>
    </div>
    <div class="box">
      <h3>
        Samsung Galaxy S4
      </h3>
      <p float="left">
        <img src="images/item3.jpg" width="50%" height="200px" alt="item3"/>
      </p>
      <h4>
        500$
      </h4>
    </div>
    <div class="box">
      <h3>
        Liquid Perfume
      </h3>
      <p float="left">
        <img src="images/item4.gif" width="50%" height="200px" alt="item4"/>
      </p>
      <h4>
        10$
      </h4>
    </div>
    <div class="box">
      <h3>
        ASUS Laptop i3
      </h3>
      <p float="left">
        <img src="images/item5.png" width="50%" height="200px" alt="item5"/>
      </p>
      <h4>
        400$
      </h4>
    </div>
    <div class="box">
      <h3>
        Sony PS2 VGA
      </h3>
      <p float="left">
        <img src="images/item6.jpg" width="50%" height="200px" alt="item6"/>
      </p>
      <h4>
        7$
      </h4>
    </div>
    <div class="box">
      <h3>
        8GB Memory Card
      </h3>
      <p float="left">
        <img src="images/item7.jpg" width="50%" height="200px" alt="item7"/>
      </p>
      <h4>
        12$
      </h4>
    </div>
    <div class="box">
      <h3>
        2GB DDR3 RAM
      </h3>
      <p float="left">
        <img src="images/item8.jpg" width="50%" height="200px" alt="item8"/>
      </p>
      <h4>
        20$
      </h4>
    </div>
    <div class="box">
      <h3>
        50" LED TV
      </h3>
      <p float="left">
        <img src="images/item9.jpg" width="50%" height="200px" alt="item9"/>
      </p>
      <h4>
        999$
      </h4>
    </div>
    <div class="box2">
      <a href="#">
        <h4>
          Next Page
        </h4>
      </a>
    </div>
  </center>
</div>

<div id="footer">
    test
</div>

CSS:

#wrap{
    width:90%;
    margin:0 auto;
    margin-top: 5em;
}
.box{
    float:left;
    width:30%;
    height:300px;
    margin:0 auto;
}   
.box2{
    float:right;
    width:30%;  
    margin:0 auto;
}
#footer {
    width:100%;
    height:80px;
    position:absolute;
    bottom:0;
    left:0;
    background:#ee5;
    clear: both;
}

最佳答案

您不需要使用position:absolute。正如@JimmyRare 指出的那样,绝对定位是相对于窗口定位的。所以只需删除绝对定位,您的页脚就会放回到正常的文档流中。

JSFIDDLE PROOF HERE

关于html 页脚出现在包装内?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26694498/

相关文章:

html - 网页不换行

html - 是否可以使用纯 CSS 水平设置嵌套列表的每个级别的样式?

jquery - 是否可以将我的页面格式保持为纵向模式(移动设备)

javascript - Opera SDK开发

css - 如何更改 HTML 中进度条值的颜色?

html - 垂直居中,绝对定位,多元素

jQuery:当滚动超过某个点时,fadeIn 固定导航

html - 在链接中隐藏 .html 扩展名

javascript - 使用jsPDF在服务器端保存pdf

javascript - 移动浏览器故障中的 CSS 自动溢出