[英]Vertically align text with different font sizes
I have a jsfiddle here - http://jsfiddle.net/8bnLkyLv/ 我在这里有一个jsfiddle- http://jsfiddle.net/8bnLkyLv/
<div class="alert">
<p><i class="fa fa-exclamation-triangle"></i>This is some text</p>
</div>
It's super simple, <p>
tag that contains a <i>
tag that containers a font awesome icon. 这是一个非常简单的
<p>
标签,其中包含一个<i>
标签,该标签包含一个字体超棒的图标。
The <i>
tag needs to be bigger than the text. <i>
标记必须大于文本。
I need the text and the icon to be centered horizontally in the red container. 我需要文本和图标在红色容器中水平居中。
I know I could to it by absolutely positioning the <i>
tag but that seems like a lot of messing for something so simple. 我知道我可以通过绝对定位
<i>
标签来做到这一点,但是对于这么简单的事情来说,这似乎很麻烦。
Simply give the bigger inline-level element - the <i>
element in this case - a vertical-align
of middle
. 只需为较大的内联级别元素(在这种情况下为
<i>
元素)设置为middle
的vertical-align
。
.alert { background: red; font-family: sans-serif; text-align: center; } .alert p { color: white; display: inline-block; padding: 5px 0; vertical-align: center; } .alert pi { font-size: 2em; padding: 0 10px 0 0; vertical-align: middle; /* <-- Added declaration */ }
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/> <div class="alert"> <p> <i class="fa fa-exclamation-triangle"></i> This is some text </p> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.