Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a div to float to the bottom of its container?

I have floated images and inset boxes at the top of a container using float:right (or left) many times. Now, I need to float a div to the bottom right corner of another div with the normal text wrap that you get with float (text wrapped above and to the left only).

I thought this must be relatively easy even though float has no bottom value but I haven't been able to do it using a number of techniques and searching the web hasn't come up with anything other than using absolute positioning but this doesn't give the correct word wrap behaviour.

I had thought this would be a very common design but apparently it isn't. If nobody has a suggestion I'll have to break my text up into separate boxes and align the div manually but that is rather precarious and I'd hate to have to do it on every page that needs it.

like image 262
Stephen Martin Avatar asked Nov 23 '08 01:11

Stephen Martin


People also ask

How do I anchor a div to the bottom of a div?

Just set the parent div with position:relative . Then, the inner item you want to stick to the bottom, just use position:absolute to stick it to the bottom of the item.

How do I place a div at the bottom without absolute?

Without using position: absolute , you'd have to vertically align it. You can use vertical-align: bottom which, according to the docs: The vertical-align CSS property specifies the vertical alignment of an inline or table-cell box.


2 Answers

Set the parent div to position: relative, then the inner div to...

position: absolute;  bottom: 0; 

...and there you go :)

like image 131
Timothy Khouri Avatar answered Sep 20 '22 15:09

Timothy Khouri


A way to make it work is the following:

  • Float your elements left like normal
  • Rotate the parent div 180 degrees using

    -moz-transform:rotate(180deg); -webkit-transform:rotate(180deg); -o-transform:rotate(180deg); -ms-transform:rotate(180deg); filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=2); 

    JSfiddle: http://jsfiddle.net/wcneY/

  • Now rotate all the elements that float left (give them a class) 180 degrees to put them straight again. Voila! they float to the bottom.

like image 33
Tom Groentjes Avatar answered Sep 19 '22 15:09

Tom Groentjes