I've the following HTML:
<div id="parent" style="height: 300px; position: relative">
<div id="child" style="width: 100px; height: 50px; bottom: 0; position: absolute">
... content ...
</div>
</div>
In this HTML I've positioned #child
at the bottom of #parent
using absolute positioning.
However I'd also like to center #child
within #parent
. Parent's width changes through its use case so I can't just calculate it in pixels and apply half of pixels (to center) to child's left
property.
Applying text-align: center
to #parent
doesn't center #child
as it's absolutely positioned.
Applying text-align: center
to #child
centers content within child and doesn't affects its own positioning.
Any ideas how to center #child
within #parent
without JavaScript, if parent sometimes dynamically changes it's width?