Click here to Skip to main content
15,894,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
CSS
.div1{
    display: inline-block;
    width: 49%;
	border:1px solid red;
	height:250px;
}

.div2{
    display: inline-block;
    width: 49%;
	
	border:1px solid red;
}


.div3{
    display: inline-block;
    width: 49%;
	border:1px solid red;
	vertical-align:top;
	
}


.div4{
    display: inline-block;
    width: 49%;
	border:1px solid red;
}


HTML
<div class="div1">
  some content1
</div><!-- 
--><div class="div2">
  some content2
</div><!-- 
--><div class="div3">
  some content3
</div><!-- 
--><div class="div4">
  some content4
</div>


What I have tried:

There is gap between some content 2 and some content 4
So why blank space create I am able t understand

some content1 some content 2
Some content4

Some content 4

So theere gap between 2 and 4 why this gap created not able to understand
can any tell me please
Posted
Updated 19-Aug-17 20:18pm
v3

1 solution

There is a gap between content 2 and content 4 because .div2 doesn't have a height set, and divs side-by-side are not automatically aligned.

There are two options: either you put a height on .div2, or you use flexbox. In my opinion, flexbox is the cleanest way to do this.

How to do that here: you wrap div1 and div2 in a parent div, and you give it the class row:
HTML
<div class="row"><div class="div1">
  some content1
</div><div class="div2">
  some content2
 </div></div><div class="div3">
  some content3
</div><div class="div4">
  some content4
</div>

And in your CSS, you add this:
CSS
.row {
  display: flex;
}

That's all you need here!

You can do a lot more with flexboxes. If you're interested, take a look at Using CSS Flexible Boxes - CSS | MDN[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900