如何使两个布局列具有相同的高度,右列偏移到标题

时间:2011-01-11 06:38:50

标签: css

我想创建一个具有2列布局的博客设计,右列位于顶部与标题相同但我也希望它的高度在页脚上接近,而不管左列的内容如何。

这是我想要的布局:

alt text

CSS代码:

#center {
    float: left;
    overflow: hidden;
    background: #f0f0f0;
}
#center div {
    float: left;
    margin-bottom: -2000px;
    padding-bottom: 2000px;
}
#center .col1 {
    width:700px;
    margin-right: 5px;
}
#center .col2 {
    margin-right: 0;
    width:200px;
    background:#000000;
    overflow:hidden;

}
.clear {
    clear:both;
    display:block;
    overflow:hidden;
    visibility:hidden;
    width:0;
    height:0
}
.content {
    padding:10px;
}
.footer {
    background:#99FF99;
}
.sidebar {
    margin-left: 5px;
    margin-right: 5px;
    color:#FFFFFF;
}
#Image1 {
    position:absolute;
    top:10px;
}

HTML代码:

<div class="container">
  <div class="header-wrapper">
    <div class="header">
    <h1>Blog Title</h1>
    Integer nec neque. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent dictum venenatis velit. Morbi interdum eleifend sapien. Morbi a mauris</div>
  </div>
</div>
<div class="clear"></div>
<div class="container">
  <div id="center" class="grid">
    <div class="col1">
      <div class="content">
        <p>Left Content</p>
      </div>
    </div>
    <div class="col2">
      <div class="content sidebar">
        <div id="Image1" class="widget Image">
          <div class="widget-content"> <img width="180" height="201" src="Image SRc" id="Image1_img" alt=""> <br>
          </div>
        </div>
        <p>righ text</p>
      </div>
    </div>
  </div>
</div>
<div class="clear"></div>
<div class="container">
  <div class="footer">Footer</div>
</div>

1 个答案:

答案 0 :(得分:1)

如果您只想在没有旅程的情况下得到答案,请点击此处:

<强> CSS:

<style media="screen" type="text/css">
    #container2 {
        clear:left;
        float:left;
        width:100%;
        overflow:hidden;
        background:#ffa7a7; /* column 2 background colour */
    }
    #container1 {
        float:left;
        width:100%;
        position:relative;
        right:50%;
        background:#fff689; /* column 1 background colour */
    }
    #col1 {
        float:left;
        width:46%;
        position:relative;
        left:52%;
        overflow:hidden;
    }
    #col2 {
        float:left;
        width:46%;
        position:relative;
        left:56%;
        overflow:hidden;
    }
    #footer {
        clear:both;
        float:left;
        width:100%;
    }
</style>

<强> HTML

<div id="header">
</div>
<div id="container2">
    <div id="container1">
        <div id="col1">
        </div>
        <div id="col2">
        </div>
    </div>
</div>
<div id="footer">
</div>

DEMO