[英]How to set vertical-align of span to middle of a div
I test vertical-align with a simple html code, but it doesn't work 我使用简单的html代码测试vertical-align,但它不起作用
<div style="height:45px; border: solid 1px black;">
<strong style="vertical-align:bottom;">
abc
</strong>
</div>
This is how you do it 这就是你如何做到的
<div style="height:45px; border: solid 1px black; display: table;">
<strong style="vertical-align:bottom; display: table-cell;">
abc
</strong>
</div>
As I have mentioned before, vertical aligns are very tricky. 正如我之前提到的,垂直对齐非常棘手。 For this to work, like it did on table, set the parent container to display as table
and the inner <div>
s or elements
to display as table-cell
要使其工作,就像在表上一样,将父容器设置为显示为table
,将内部<div>
或elements
设置为table-cell
Give the parent box (in your case div
) a height
, display: table-cell
and vertical-align: middle
properties. 给父框(在你的案例div
)一个height
, display: table-cell
和vertical-align: middle
属性。 Here is the example: 这是一个例子:
<div style="height:100px; border: solid 1px black; vertical-align:middle;display:table-cell;">
<span style="">abc</span>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.