English 中文(简体)
边框和等高css列
原标题:Borders and equal height css columns

我有这样的代码

<div class="container">
  <div class="section">
    <div class="left">
      a profile pic and some text
    </div>
    <div class="right">
      a wider div with much more text and some bio info
  </div>
</div>

我希望在两个div之间有一个虚线边框,将左栏和右栏分隔开。我的问题是,无论我把边框放在左栏还是右栏,它都不会伸到底。如果其中一列比另一列短/长,则边界总是在到达看起来被截断的底部之前停止。

问题回答

试试这个:

 html,body,.container, .section, .left, .right{height:100%}
  .left, .right {border:1px dotted black;float:left;}

示例:http://jsbin.com/agaza5

使左右div都伸展到容器的整个高度(部分)。

.left{ height:100%; }
.right{ height: 100%; }

我会设置部分div的高度,然后将children的高度设置为100%。

查看

使用CSS为两个div列设置相等的height属性:

.left {
    border:1px solid #ccc;
    height:100px; /* you can use "100%" too, if you want */
}


.right {
    height:100px; /* you can use "100%" too, if you want */
}

如果您想为两个div创建相同的最小高度,但如果内容增加,只允许一个div进一步扩展,那么您也可以使用min-height属性。

我还要补充一点,您应该为div使用更多语义名称。如果有一天你决定移动你的左栏,但它已经不在左边了,该怎么办?你必须重命名所有内容!





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签