Reputation: 485
I want to know how it is possible for child div to occupy parent div height.
The below code is my html:
<div class="container">
<div class="header width100p">
<h2>
Header
</h2>
</div>
<div class="content width100p">
<div class="width29p npv">
<div class="width100p inner">
<p>
navigation
</p>
<p>
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
</p>
</div>
</div>
<div class="rtb">
<div class="width100p ql">
<p>
div one
</p>
<p>
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
</p>
</div>
<div class="width100p mtbs">
<p>
div two
</p>
<p>
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
</p>
</div>
<div class="floatL width100p widdiv">
<div class="floatL width100p">
<div class="floatL width40p incont">
<p>
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
</p>
<p>
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
</p>
<p>
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
</p>
<p>
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
</p>
</div>
<div class="floatL width40p incont">
<p>
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
</p>
</div>
</div>
<div class="floatL width100p">
<div class="floatL width40p incont">
<p>
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
</p>
</div>
<div class="floatL width40p incont">
<p>
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
</p>
<p>
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
</p>
<p>
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
</p>
<p>
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
</p>
</div>
</div>
</div>
<div class="clear"></div>
</div>
</div>
<div class="footer width100p">
<h2>
Footer
</h2>
</div>
</div>
The respective styles are:
<style>
*,html{
margin: 0;
padding: 0;
}
html{
height: 100%;
}
.container{
width:960px;
margin:20px auto;
}
.header h2,.footer h2{
text-align: center;
}
.floatL{
float: left;
}
.floatR{
float: right;
}
.clear{
clear:both;
}
.width100p{
width: 100%;
}
.width29p{
width: 29%;
}
.width70p{
width: 70.8%;
}
.header,.footer,.content{
border:1px solid #000;
}
.npv{
border-right: 1px solid #000;
}
.ql,.mtbs{
border-bottom: 1px solid #000;
}
.content{
display: table;
}
.npv, .rtb{
display: table-cell;
}
.width40p{
width: 40%;
}
.incont{
margin: 4%;
background: #ccc;
border:1px solid red;
}
</style>
I want to know how the (.inner) child div can occupy the height of its parent div(.npv). I have tried applying height:100% !important to both .inner and .npv but still could not resolve the problem of child div occupying the parent div height. problem of occupying
Upvotes: 0
Views: 2505
Reputation: 127
Have a similar kind of example on "Increase the height of a nested(child) div to the occupy the height of its parent div" which you might use as a reference.
suggestion:
- for parent div set position:absolute
- for child div set position:absolute; height:100%;
or
position:absolute; top:0; bottom:0;
Upvotes: 0
Reputation: 28292
Set the height and width to 100%:
.width100p{
height: 100%; // or set height and width in pixels
width: 100%;
}
.width100p .inner {
height: 100%;
width: 100%;
}
Or specify the size in your html, and display it as a block:
.width100p {
display:block;
.width100p .inner {
display:block;
}
Upvotes: 0
Reputation: 1318
markup
<html>
<body>
<div class="outer">
<div class="inner">
</div>
</body>
</html>
css
html, body {
height: 100%;
width: 100%;
}
.outer {
height: 100%; // or set height and width in pixels
width: 100%;
}
.outer .inner {
height: 100%;
width: 100%;
}
For the percentage heights to work,
you need to set the heights of each and every parent in its heirarchy.
including html, and body tags.
Upvotes: 1