浮动div与clear&填充宽度

时间:2014-02-18 10:19:14

标签: css html responsive-design

我有一个问题,我想设置3个浮动的div,在底部我想要一个页脚。所以我得到了这两个解决方案,但它不起作用。请查看图片:

enter image description here

这里的问题是内容未被清除,因此页脚不会改变位置:

<div class="container">
  <div class="left"><div class="content"><div class="right">
  <div style="clear:left;"></div>
</div>
<div class="footer"></div>


.container {
  height: auto !important;
  min-height: 100%;
}

.left {
  float: left;
  width: 20%;
  max-width: 200px;
}
.center {
  float: left;
  width: 80%;
  max-width: 500px;
}
.right {
  width: auto;
}

.content {
  height: auto !important;
  height: 100%;
  min-height: 100%;
}

.footer {
  height: 202px;
  margin: -202px auto 0;
  position: relative;
}

如果我清除了内容,我会得到正确的div进入下一行的结果:

enter image description here

谢谢!

2 个答案:

答案 0 :(得分:0)

我玩了一下。我认为您的html结构不适合您尝试创建的效果。

这是一个新的例子:

<强> HTML

<div class="container">
   <div class="left">
   </div>

   <div class="center">
   </div>

   <div class="right">
   </div>

   <div style="clear">

   <div class="content">
   </div>

   <div class="footer">
   </div>
</div>

<强> CSS

.container { 
    height: auto !important; 
    min-height: 100%; 
}

.left {   
    float: left; 
    width: 20%; 
    max-width: 200px; 
    min-height: 100px;
    background: red;
}
.center { 
    float: left; 
    width: 80%; 
    max-width: 500px; 
    min-height: 100px;
    background: blue;
}
.right {  
    width: auto; 
    min-height: 100px;
    background: green;
}

.content {
 height: auto !important;
 height: 100%;
    min-height: 100px;
    width: 80%;
    max-width: 500px;
    margin: 0 auto;
    background: yellow;
}

.footer { 
    height: 202px; 
    margin: 0 auto; 
    position: relative; 
    background: purple;
}

我在这个小提琴中重新安排了一切: http://jsfiddle.net/LJQCx/2/

我希望这是你想要实现的目标。

答案 1 :(得分:0)

以下代码希望它有助于检查fiddle

<div class="page-wrap">
<div class="container">
    <div class="left">
        <p>I am Left</p>
    </div>
    <div class="center">
        <p>I am Center</p>
    </div>
    <div class="right">
        <p>I am Right</p>
    </div>
    <div class="clear"></div>
</div>
</div>
<div class="footer">
    <p>I am Footer</p>
</div>

* { margin: 0;}
html, body { height: 100%;}
.page-wrap {min-height: 100%;/* equal to footer height */margin-bottom: -142px; }
.page-wrap:after { content: ""; display: block;}
.footer, .page-wrap:after { /* .push must be the same height as footer */ height: 142px;}
.site-footer {}
.container{ width:100%;}
.left{ float:left; width:25%;}
.center{float:left; width:50%;}
.right{float:left; width:25%;}