DEMO can be found at:
http://www.bootply.com/VZ7gvA7ndE#
I set the height of div
to 100px and want to show the label
at the bottom of the div
. I use
#contain-word-lab {
vertical-align: bottom;
margin-bottom: 5px;
}
However, this doesn't work at all. The label
still align to the top of the div
.
Does anyone have any ideas about this? Why vertical-align
doesn't work here? Thanks!
vertical-align
only applies to table cells. If you want to position an element at the bottom of its parent, you need to give itposition: absolute;
andbottom: 0;
.quick example
http://jsfiddle.net/oa2gmuq3/
if you add
to the label it likes to keep it at the bottom
Try to do following
FIDDLE DEMO
Apply
position:relative
to the parent div and make your label asposition:absolute
.DEMO
Why
vertical-align: bottom
is not working aloneSince the height of the parent element is greater than the computed height of the label, Using
vertical-align: bottom
won't move that (inline) element to the bottom of the parent.Because in an inline flow,
vertical-align
determines how the elements are positioned based on their parent's baseline; And using that property on the label won't alter the position of baseline of its parent.Inline level elements (
inline
,inline-block
) are sitting in their baseline by default. And if they have different heights, the tallest element will determine where the others whould be placed.I.e. In an inline flow, the tallest element will affect/move the baseline of the parent:
Looking for a solution
Hence in cases where the parent has an explicit
height
, if we could have an inline child which has the exact same height as the parent (a full-height child), it would affect the inline flow and move the baseline down:And in order to keep elements (including letters having descenders) within the parent, we should align them vertically by
vertical-align: bottom;
declaration.Putting it all together
Therefore you could create a full-height element (Personally I'd rather go with pseudo-elements) within the parent to align the label at the bottom.
EXAMPLE HERE
set it as position:absolute;