简体   繁体   English

如何拉伸垂直div元素以填充父容器?

[英]How to stretch vertical div element to fill parent container?

I have the following JS Bin 我有以下JS Bin

<div class="container">
  <div class="column">
    <div class="cell">Top left</div>
    <div class="cell">Top left bottom</div>
  </div>
  <div class="column">
    <div class="cell">Center</div>
  </div>
  <div class="column">
    <div class="cell">Top right</div>
    <div class="cell">Top right bottom</div>
  </div>
</div>

How can I make vertical aligned divs without explicit setting of height and position to absolute to look like the following: 如何在不将高度和位置显式设置为绝对的情况下使垂直对齐的div看起来如下所示:

EDIT: Please don't suggest me using of tables because I need to resolve my problem in the example above. 编辑:请不要建议我使用表格,因为我需要在上面的示例中解决我的问题。

在此处输入图片说明

How about using CSS tables with your current markup: 如何在当前标记中使用CSS表

FIDDLE 小提琴

CSS CSS

.container {
    display: table;
}

.column {
    display: table-cell;
    vertical-align: top;
}

.cell {
    border: 1px solid #000;
    width: 100px;
    font-size: 13px;    
}
.column:nth-child(2)
{
    border: 1px solid #000;
}
.column:nth-child(2) .cell
{
    border: none;
}

Add this to your stylesheet: 将此添加到您的样式表:

.column:nth-child(2) .cell {
    padding-bottom: 18px;
}

DEMO DEMO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM