Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vertical-align:bottom WITH float:left

Tags:

css

how could i do vertical-align:bottom for some divs that have float:left?

you can see the source here: http://jsfiddle.net/Lb1su4w2/


this is what i have: (every color is a different div) enter image description here

this is what i want to have: enter image description here

like image 711
ldoroni Avatar asked Nov 15 '14 09:11

ldoroni


People also ask

How do you vertically align floated elements?

By creating a wrapper around the content you want floated, you can then use the ::after or ::before pseudo selectors to vertically align your content within the wrapper. You can adjust the size of that content all you want without it affecting the alignment.

What does vertical-align bottom do?

Aligns the top of the element and its descendants with the top of the entire line. bottom. Aligns the bottom of the element and its descendants with the bottom of the entire line. For elements that do not have a baseline, the bottom margin edge is used instead.

How do I align text at the bottom of the container?

display:flex on the container. flex-direction: column will distribute children from top to bottom. margin-top: auto to the element that you want to stick at the bottom, flex will apply all the free space above.


1 Answers

Vertical align only works with inline block elements, floated elements ignore the vertical align property.

Update the box class with the following:

.box {
    display: inline-block;
    vertical-align: bottom;
    width:80px;
}

I would make them all inline block elements and remove the whitespace with one of these techniques.

Updated fiddle: http://jsfiddle.net/9rcnLb8n/

Alternatively you could use flexbox with the align-self: flex-end; property.

like image 93
nickspiel Avatar answered Sep 27 '22 21:09

nickspiel