Reputation: 519
I want one <div>
to be on the top, three for in the middle in a row and one on the bottom without remaining spaces. And I cannot remove the space between the middle <div>
s and the bottom one.
The height of the top and the bottom ones is 15%; while the middle ones have 70%. And the bottom one is slightly out of .container
.
This is <body>
tag.
<div id="wrap">
<div class="container">
<div></div><div></div><div></div><div></div><div></div>
</div>
</div>
And this is css style.
#wrap{
width: 90%;
height: 500px;
margin: 0 auto;
border: 4px solid black;}
.container{
width: 93.75%;
height: 492px;
margin: 0 auto;
border: 4px solid black;}
.container div{
/*display: block;*/
height: 100%;}
.container div:first-child{
height: 15%;
background: #003153;}
.container div:first-child +div{
display: inline-block;
width: 33.33333333333333333%;
height: 70%;
background: #c33;}
.container div:first-child +div +div{
display: inline-block;
width: 33.33333333333333333%;
height: 70%;
background: #2dcc70;}
.container div:first-child +div +div +div{
display: inline-block;
width: 33.33333333333333333%;
height: 70%;
background: #e75d5d;}
.container div:first-child +div +div +div +div{
/*display: block;*/
height: 15%;
background: #003153;}
Do I have to deal with this by modifying display:
or something?
Upvotes: 2
Views: 60
Reputation: 1416
Here is working code-
#wrap{
width: 90%;
height: 500px;
margin: 0 auto;
border: 4px solid black;}
.container{
width: 93.75%;
height: 492px;
margin: 0 auto;
border: 4px solid black;}
.container div{
vertical-align: top;
/*display: block;*/
height: 100%;}
.container div:first-child{
height: 15%;
background: #003153;}
.container div:first-child +div{
display: inline-block;
width: 33.33333333333333333%;
height: 70%;
background: #c33;}
.container div:first-child +div +div{
display: inline-block;
width: 33.33333333333333333%;
height: 70%;
background: #2dcc70;}
.container div:first-child +div +div +div{
display: inline-block;
width: 33.33333333333333333%;
height: 70%;
background: #e75d5d;}
.container div:first-child +div +div +div +div{
/*display: block;*/
height: 15%;
background: #003153;}
<div id="wrap">
<div class="container">
<div></div><div></div><div></div><div></div><div></div>
</div>
</div>
Upvotes: 0
Reputation: 39392
Use vertical-align: top
with display: inline-block
. Default value is baseline
.
From Documentation:
baseline
: Aligns the baseline of the element with the baseline of its parent.
#wrap{
width: 90%;
height: 500px;
margin: 0 auto;
border: 4px solid black;}
.container{
width: 93.75%;
height: 492px;
margin: 0 auto;
border: 4px solid black;}
.container div{
/*display: block;*/
height: 100%;}
.container div:first-child{
height: 15%;
background: #003153;}
.container div:first-child +div{
display: inline-block;
vertical-align: top;
width: 33.33333333333333333%;
height: 70%;
background: #c33;
}
.container div:first-child +div +div{
display: inline-block;
vertical-align: top;
width: 33.33333333333333333%;
height: 70%;
background: #2dcc70;}
.container div:first-child +div +div +div{
display: inline-block;
vertical-align: top;
width: 33.33333333333333333%;
height: 70%;
background: #e75d5d;}
.container div:first-child +div +div +div +div{
/*display: block;*/
height: 15%;
background: #003153;}
<div id="wrap">
<div class="container">
<div></div><div></div><div></div><div></div><div></div>
</div>
</div>
Upvotes: 4