Skip to content Skip to sidebar Skip to footer

How To Vertical Align Bottom

Consider the following HTML and CSS: HTML
<

Solution 1:

I originally though that changing .bar to display:table-cell, would work, (example) however, in doing that, the cell takes the same height as the parent element.

The only solution that comes to mind is wrapping the span elements:

<divclass="eq"><divid="bars"><spanclass="bar"></span>
    ...
    <spanclass="bar"></span></div></div>

and then using the following CSS (example) - it works.

.bar {
    background-color: green;
    width:15px;
    height:40px;
    display: inline-block;
    vertical-align:bottom;
}
#bars {
    display:table-cell;
    vertical-align:bottom;
}
.eq {
    min-height:100px;
    border:1px solid black;
    display:table;
}

Basically, we assign display:table-cell, and vertical-align:bottom to the wrapping element, #bars. This works for varying heights. (example)

Note, that the spacing between the .bar elements is because of the fact that they are inline-block elements. If you want to prevent that, see this (example).

Solution 2:

Just give a line-height to your div container, which is equal to the div's height.

line-height: 50px;

Here is the JSFiddle.

Post a Comment for "How To Vertical Align Bottom"