Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to put two divs on same line using inline-block

Tags:

html

css

I am trying to place two divs on same line.

<div id="page">
    <div id="first-box">   
    </div>
    <div id="second-box">
        this is second box
    </div>  
 </div>

css

div#page {
   background-color: slategrey;
   width: 960px;
   height:900px;
   margin: 20px;
   padding:20px;
   border:4px solid blue;
}
div#first-box{
   width:200px;
   height:200px;
   display:inline-block;
   border:1px groove black;
}
div#second-box{
   display:inline-block;
   width:200px;
   height:200px;
   padding:10px;
   border:1px solid green;
}

it place itself in same line when I use vertical-align:top in the second-box. But why it behave like that? Thanks http://codepen.io/rajinirajadev/pen/xgBVab

like image 322
rajini raja Avatar asked Nov 30 '25 11:11

rajini raja


1 Answers

add this line in your second-box's css:

div#second-box{
  display:inline-block;
  width:200px;
  height:200px;
  padding:10px;
  border:1px solid green;
  vertical-align: top; // add this line
}
like image 200
amansoni211 Avatar answered Dec 02 '25 01:12

amansoni211



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!