如何垂直对齐 2 种不同大小的文本? [英] How to vertically align 2 different sizes of text?
问题描述
我知道要将文本垂直对齐到块的中间,您可以将行高设置为与块相同的高度.
但是,如果我有一个句子中间有一个词,那就是2em
.如果整个句子的行高与包含块相同,则较大的文本垂直对齐,但较小的文本与较大的文本在同一基线上.
如何设置它使两种大小的文本垂直对齐,以便较大的文本比较小的文本在基线上更低?
在内联容器上尝试 vertical-align:middle;
?
它可以工作,但您的所有文本都必须在内联容器中,如下所示:
<div style="height:100px; line-height:100px; background:#EEE;"><span style="vertical-align:middle;">test</span><span style="font-size:2em; vertical-align:middle;">test</span>
I know to vertically align text to the middle of a block, you set the line-height to the same height of the block.
However, if I have a sentence with a word in the middle, that is 2em
. If the entire sentence has a line-height the same as the containing block, then the larger text is vertically aligned but the smaller text is on the same baseline as the larger text.
How can I set it so both sizes of text are vertically aligned, so the larger text will be on a baseline lower than the smaller text?
Try vertical-align:middle;
on inline containers?
EDIT : it works but all your text must be in an inline container, like this :
<div style="height:100px; line-height:100px; background:#EEE;">
<span style="vertical-align:middle;">test</span>
<span style="font-size:2em; vertical-align:middle;">test</span>
</div>
这篇关于如何垂直对齐 2 种不同大小的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!