如何垂直对齐2种不同大小的文本? [英] How to vertically align 2 different sizes of text?
本文介绍了如何垂直对齐2种不同大小的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道将文本垂直对齐到块的中间,您将行高设置为与块的高度相同。
I know to vertically align text to the middle of a block, you set the line-height to the same height of the block.
但是,如果我有一个在中间有一个单词的句子,即 2em
。如果整个句子具有与包含块相同的行高,则较大的文本是垂直对齐的,但较小的文本与较大文本在相同的基线上。
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.
推荐答案
在内联容器中尝试 vertical-align:middle;
?
所有文字必须位于内置容器中,如下所示:
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屋!
查看全文