Given the following HTML:
<div id="container">
<!-- Other elements here -->
<div id="copyright">
Copyright Foo web designs
</div>
</div>
I would like #copyright
to stick to the bottom of #container
.
Can I achieve this without using absolute positioning? If the float property supported a value of 'bottom' it seems that would do the trick, but unfortunately, it doesn't.
Its an old question, but this is a unique approach that can help in several cases.
Pure CSS, Without Absolute positioning, Without Fixing any Height, Cross-Browser (IE9+)
check out that Working Fiddle
Because normal flow is 'top-to-bottom' we can't simply ask the
#copyright
div to stick to the bottom of his parent without absolutely positioning of some sort, But if we wanted the#copyright
div to stick to the top of his parent, it will be very simple - because this is the normal flow way.So we will use this in our advantage. we will change the order of the
div
s in the HTML, now the#copyright
div is at the top, and the content follow it right away. we also make the content div stretch all the way (using pseudo elements and clearing techniques)now it's just a matter of inverting that order back in the view. that can be easily done with CSS transform.
We rotate the container by 180deg, and now: up-is-down. (and we inverse back the content to look normal again)
If we want to have a scroolbar within the content area, we need to apply a little bit more of CSS magic. as can be showed Here [in that example, the content is below a header - but its the same idea]
Create another container
div
for the elements above#copyright
. Just above copyright add a newdiv
:<div style="clear:both;"></div>
It will force the footer to be under everything else, just like in the case of using relative positioning (bottom:0px;
).The flexbox approach!
In supported browsers, you can use the following:
Example Here
The solution above is probably more flexible, however, here is an alternative solution:
Example Here
As a side note, you may want to add vendor prefixes for additional support.
Also, if there's stipulations with using
position:absolute;
orposition:relative;
, you can always trypadding
parentdiv
or putting amargin-top:x;
. Not a very good method in most cases, but it may come in handy in some cases.Using the translateY and top property
Just set element child to position: relative and than move it top: 100% (that's the 100% height of the parent) and stick to bottom of parent by transform: translateY(-100%) (that's -100% of the height of the child).
BenefitS
But still just workaround :(
Don't forget prefixes for the older browser.
For those only have one child in the container, you can use the
table-cell
andvertical-align
approach which worked reliably for positioning a single div at the bottom of its parent.Note that using
table-footer-group
as other answers mentioned will break the height calculation of parenttable
.