[英]Vertically align an inline-block next to an inline-block that is taller
I want to vertically align the image .b so that it's in the center of the text (vertically). 我想垂直对齐图像.b,以使其位于文本的中心(垂直)。
I think I understand vertical-align, and it does not help me because it aligns according to the baseline of .b, which is near the bottom of the #container. 我想我了解垂直对齐方式,但对我没有帮助,因为它根据.b的基线对齐,该基线靠近#容器的底部。
What is the correct practice to do so? 这样做的正确做法是什么? I would like to avoid setting a margin from the top.
我想避免从顶部设置边距。 I basically want to align according to the parent container height and not the baseline, is it possible/right?
我基本上想根据父容器的高度而不是基线对齐,这可能吗?
codepen: http://codepen.io/Vall3y/pen/vEONaJ codepen: http ://codepen.io/Vall3y/pen/vEONaJ
html: HTML:
<div id='container'>
<div class="a"></div>
<div class="b">
text text text text text text text text text text text text text text text text text text text text text text text text text text text
</div>
</div>
css: CSS:
#container {
width: 100px;
font-size: 0;
}
#container > div {
display: inline-block;
}
.a {
width: 30px;
height: 30px;
background-size: 100% 100%;
background-repeat: no-repeat;
display: inline-block;
position: relative;
background-image: url(http://upload.wikimedia.org/wikipedia/en/f/f4/Free_Blue_Star.jpg)
}
.b {
width: 70px;
font-size: 14px;
}
Just put vertical-align: middle;
只是
vertical-align: middle;
on both .a and .b and that will work. 在.a和.b上都可以使用。
you could of course just give .ba padding and a background image with a background position of left center
while removing .a 您当然可以在删除.a的同时给.ba填充和背景图片,其背景位置为
left center
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.