I'm trying to get several inline
and inline-block
components aligned vertically in a div
. How come the span
in this example insists on being pushed down? I've tried both vertical-align:middle;
and vertical-align:top;
, but nothing changes.
HTML:
<div>
<a></a><a></a>
<span>Some text</span>
</div>
CSS:
a {
background-color:#FFF;
width:20px;
height:20px;
display:inline-block;
border:solid black 1px;
}
div {
background:yellow;
vertical-align:middle;
}
span {
background:red;
}
RESULT:
Give
vertical-align:top;
ina
&span
. Like this:Check this http://jsfiddle.net/TFPx8/10/
Simply floating both elements left achieves the same result.
vertical-align
applies to the elements being aligned, not their parent element. To vertically align the div's children, do this instead:See: http://jsfiddle.net/dfmx123/TFPx8/1186/
NOTE:
vertical-align
is relative to the current text line, not the full height of the parentdiv
. If you wanted the parentdiv
to be taller and still have the elements vertically centered, set thediv
'sline-height
property instead of itsheight
. Follow jsfiddle link above for an example.