gpt4 book ai didi

html - 垂直对齐 : middle doesn't work

转载 作者:技术小花猫 更新时间:2023-10-29 11:38:27 25 4
gpt4 key购买 nike

css 属性 vertical-align: middle 在此示例中不起作用。

HTML:

<div>
<span class='twoline'>Two line text</span>
<span class='float'> Float right </span>
</div>

CSS:

.float {
float: right;
}

.twoline {
width: 50px;
display: inline-block;
}

div {
border: solid 1px blue;
vertical-align: middle;
}

右侧 float 的 span 相对于包含它的 div 没有垂直居中。我怎样才能让它垂直居中?

以上代码在this fiddle中.

最佳答案

您必须使用 display 将您的元素包装在 table-cell 中,在 table 中。

像这样:

<div>
<span class='twoline'>Two line text</span>
<span class='float'>Float right</span>
</div>

.float {
display: table-cell;
vertical-align: middle;
text-align: right;
}
.twoline {
width: 50px;
display: table-cell;
}
div {
display: table;
border: solid 1px blue;
width: 500px;
height: 100px;
}

此处显示:http://jsfiddle.net/e8ESb/7/

关于html - 垂直对齐 : middle doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7967217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com