Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

two DIV side by side and aligned vertically at their bottom

Tags:

html

css

I need two DIV to be put side by side and aligned vertically at their bottom.

  • The orange div doesn't have a width or height. It can grow depending of his content
  • I should be able to use padding and margin of the green div
  • I would like to have a solution that doesn't use javascript

a tall orange rect, a short green rect, base aligned

like image 371
Alexandre Jobin Avatar asked Nov 08 '11 21:11

Alexandre Jobin


People also ask

How do I align two divs side by side vertically?

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 align the bottom of two divs?

The easiest way to do this and keep the fluid content in the orange div would be to put both of the divs inside a table and use valign bottom to keep both divs at the bottom no matter how big the orange div gets. This can be done with pure css but the table is the easiest way.

How do I vertically align a div to the bottom?

The best possible solution to move a div to the bottom is as follows. Basically what you need to do is to set display flex and flex-direction as a column to the parent and add a 'margin-top: auto' to its child which needs to be floated to the bottom of the container Note: I have used bootstrap and its classes.

How do I align two divs on the same line?

To display multiple div tags in the same line, we can use the float property in CSS styles. The float property takes left, right,none(default value) and inherit as values. The value left indicates the div tag will be made to float on the left and right to float the div tag to the right.


1 Answers

See: http://jsfiddle.net/thirtydot/J9eds/

I've used display: inline-block combined with vertical-align: bottom.

HTML:

<div id="container">     <div id="left">         left<br />left<br />left<br />left<br />left<br />left<br />         leftleftleftleftleftleft     </div>     <div id="right"></div> </div> 

CSS:

#container {     border: 1px solid red;     float: left; } #left, #right {     border: 2px solid red;     background: #ccc;      vertical-align: bottom;     display: inline-block;     /* ie6/7 */     *display: inline;     zoom: 1; } #right {     margin: 20px 20px 0 20px;     padding: 20px;     width: 100px; } 
like image 89
thirtydot Avatar answered Sep 20 '22 17:09

thirtydot