gpt4 book ai didi

css - 垂直对齐 :middle a div inside a floating div?

转载 作者:太空宇宙 更新时间:2023-11-04 02:07:07 25 4
gpt4 key购买 nike

为什么第三列中的黑色条纹没有在父 div 的中间垂直对齐?而是在顶部下方对齐一点。有办法解决吗?

https://jsfiddle.net/pr1v6Lhd/4/

HTML:

<table border="1">
<tbody>
<tr>
<td>ADMIN<br>:(</td>
<td>222387</td>
<td width='50' style='position:relative'>
<div class='data'>59853.94</div>
<div class="bar-chart-bar">
<div class="bar" style='width:50%; background-color:#B8E4F5'>
<div style="height:10px; background-color:black; width:100%;vertical-align:middle; display: inline-block"></div>
</div>
</div>
</td>
<td width="50">0</td>
<td>59853.94</td>
<td>4189.82</td>
<td>7</td>
</tr>
</tbody>
</table>

CSS:

.bar-chart-bar {
background-color: #e8e8e8;
display: block;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
}

.bar {
float: left;
height: 100%;
}

.data {

}

.table > tbody > tr > td {
vertical-align: middle;
}

table {
font-size: 12px;
}

最佳答案

在你的 .bar 类中,你可以添加

display:flex;
flex-direction:column;
justify-content:center;

以及删除

vertical-align: middle;
display: inline-block;

来自您的 .data 类。 Here是结果。这对您不起作用的原因是 vertical-align 并不真正按照您想要的方式运行,除非您的元素位于表格单元格中。参见 this有关垂直对齐的更多信息。

关于css - 垂直对齐 :middle a div inside a floating div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40515501/

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