使用display:table时,如何将内部DIV填充到外部DIV的高度?

时间:2013-02-13 20:51:08

标签: html css

我有以下HTML,可在此fiddle:

中看到
<div id="parent">
    <div id="a" class="grid_6" style="background-color: #ff00ff">
        <div class="block-border">
            <div style="background-color: #123456">
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
            </div>
        </div>
    </div>
    <div id="b" class="grid_6" style="background-color: #ffff00">
        <div class="block-border">
            <div id="xx" style="background-color: red;">
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
            </div>
        </div>
    </div>
</div>

我怎样才能使id =“xx”的DIV在高度上扩展以填充包含DIV?

1 个答案:

答案 0 :(得分:-1)

如果您将.grid_6设置为position: relative#xx设置为height: 100%; position: absolute;则应该有效。虽然,这可能不太理想。

#parent {
    display: table-row; 
}

.grid_6 {
    position: relative;
    display: table-cell;
    width: 50%;       
}

#xx {
    height: 100%;
    position: absolute; 
}

请参阅此fiddle作为工作示例。