CSS vertical alignment of inline/inline-block elements

后端 未结 4 1149
南旧
南旧 2020-11-22 09:36

I\'m trying to get several inline and inline-block components aligned vertically in a div. How come the span in this exam

4条回答
  •  一生所求
    2020-11-22 09:51

    vertical-align applies to the elements being aligned, not their parent element. To vertically align the div's children, do this instead:

    div > * {
        vertical-align:middle;  // Align children to middle of line
    }
    

    See: http://jsfiddle.net/dfmx123/TFPx8/1186/

    NOTE: vertical-align is relative to the current text line, not the full height of the parent div. If you wanted the parent div to be taller and still have the elements vertically centered, set the div's line-height property instead of its height. Follow jsfiddle link above for an example.

提交回复
热议问题