I tried to align my text to the bottom of a div from other posts and answers in stackoverflow I learned to handle this with different css properties. But I can't get it done. Basically my html
code is like this:
<div style='height:200px; float:left; border:1px solid #ff0000; position:relative;'>
<span style='position:absolute; bottom:0px;'>A Text</span>
</div>
The effect is that in FF I just get vertical line (the div in a collapsed way) and the text is written next to it. How can I prevent the div
collapsing but having the width fitting to the text?
You now can do this with Flexbox
justify-content: flex-end
now:Consult your Caniuse to see if Flexbox is right for you.
Flex Solution
It is perfectly fine if you want to go with the
display: table-cell
solution. But instead of hacking it out, we have a better way to accomplish the same usingdisplay: flex;
.flex
is something which has a decent support.In the above example, we first set the parent element to
display: flex;
and later, we usealign-self
toflex-end
. This helps you push the item to the end of theflex
parent.Old Solution (Valid if you are not willing to use
flex
)If you want to align the text to the bottom, you don't have to write so many properties for that, using
display: table-cell;
withvertical-align: bottom;
is enough(Or JSFiddle)