Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display Two <div>s Side-by-Side [duplicate]

My goal is to display two <div>s side-by-side with the content from both <div>s aligned at the top. I do not want long text in the second <div> to wrap underneath the first one.

Finally, I do not want to set the width of the second <div> because I need the markup to work in different widths.

Sample markup is below and at http://jsfiddle.net/rhEyM/.

CSS

.left-div {     float: left;     width: 100px;     height: 20px;     margin-right: 8px;     background-color: linen; } .right-div {     float: left;     margin-left: 108px;     background-color: skyblue; }​ 

HTML

<div class="left-div">     &nbsp; </div> <div class="right-div">     My requirements are <b>[A]</b> Content in the two divs should line     up at the top, <b>[B]</b> Long text in right-div should not wrap     underneath left-div, and <b>[C]</b> I do not want to specify a     width of right-div. I don't want to set the width of right-div     because this markup needs to work within different widths. </div> 

like image 360
Jonathan Wood Avatar asked Apr 04 '12 06:04

Jonathan Wood


People also ask

How do I show two divs side by side?

The most common way to place two divs side by side is by using inline-block css property. The inline-block property on the parent placed the two divs side by side and as this is inline-block the text-align feature worked here just like an inline element does.

How do I display div content side by side?

Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.

How do I make two divs display on the same line?

You can use display: inline to put the two div elements inline. Explanation: div elements are block elements, so their display style is usually display: block . You can wrap both the div elements in a span tag. Explanation: span works the same way as the div , to organize and group elements.

How do I put two containers side by side in HTML?

With CSS properties, you can easily put two <div> next to each other in HTML. Use the CSS property float to achieve this. With that, add height:100px and set margin.


1 Answers

Try to Use Flex as that is the new standard of html5.

http://jsfiddle.net/maxspan/1b431hxm/

<div id="row1">     <div id="column1">I am column one</div>     <div id="column2">I am column two</div> </div>  #row1{     display:flex;     flex-direction:row; justify-content: space-around; }  #column1{     display:flex;     flex-direction:column;  }   #column2{     display:flex;     flex-direction:column; } 
like image 83
maxspan Avatar answered Sep 21 '22 01:09

maxspan