Force div to 100% of parent div height without spe

2018-12-31 08:52发布

I have a site with the following structure:

<div id="header"></div>

<div id="main">
  <div id="navigation"></div>
  <div id="content"></div>
</div>

<div id="footer"></div>

The navigation is on the left and the content div is on the right. The information for the content div is pulled in through PHP, so it's different every time.

How to scale the navigation vertically so that its height is the same as the content div's height, no matter which page is loaded?

标签: html css scale
24条回答
姐姐魅力值爆表
2楼-- · 2018-12-31 09:22

This trick does work: Adding a final element in your section of HTML with a style of clear:both;

    <div style="clear:both;"></div>

Everything before that will be included in the height.

查看更多
孤独寂梦人
3楼-- · 2018-12-31 09:24
#main {
    overflow: hidden;
}
#navigation, #content {
    margin-bottom: -1000px;
    padding-bottom: 1000px;
}
查看更多
路过你的时光
4楼-- · 2018-12-31 09:27
#main {
   display: table;
} 
#navigation, #content {
   display: table-cell;
}

Look at this example.

查看更多
人气声优
5楼-- · 2018-12-31 09:27
.row-eq-height {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display:         flex;
 }

From:

http://getbootstrap.com.vn/examples/equal-height-columns/equal-height-columns.css

states bootstrap but you do not need bootstrap to use this. Answering this old question, as this worked for me, and seems pretty easy to implement.

This was the same answer I provided to this Question

查看更多
永恒的永恒
6楼-- · 2018-12-31 09:32

Try making the bottom margin 100%.

margin-bottom: 100%;
查看更多
弹指情弦暗扣
7楼-- · 2018-12-31 09:34

using jQuery:

$(function() {
    function unifyHeights() {
        var maxHeight = 0;
        $('#container').children('#navigation, #content').each(function() {
            var height = $(this).outerHeight();
            // alert(height);
            if ( height > maxHeight ) {
                maxHeight = height;
            }
        });
        $('#navigation, #content').css('height', maxHeight);
    }
    unifyHeights();
});
查看更多
登录 后发表回答