我需要垂直对齐CSS的盒子而不使用display: inline-block
。由于我不知道我的元素的高度,我使用了描述的方式(CSS表格方法)here。CSS垂直对齐表方法不起作用
<div style="background-color: black">
<div style="background-color: aqua; display: table; margin: auto;">
<div style="background-color: aliceblue; width: 200px; float: left; display: table-cell; vertical-align: middle;">
<p>A</p>
<p>A</p>
<p>A</p>
</div>
<div style="background-color: green; height: 20px; width: 100px; float: left; display: table-cell; vertical-align: middle;"></div>
<div style="background-color: aliceblue; width: 250px; float: left; display: table-cell; vertical-align: middle;">
<p>B</p>
<p>B</p>
<p>B</p>
<p>B</p>
</div>
</div>
</div>
但是,此测试页上的垂直对齐完全没有效果。根据这些div的计算CSS,显示值被设置为阻止!我怎样才能让这些div出现在中间?
尝试清除浮动:从DIV左 - 显示:表格 - 单元和浮动:左边没有任何意义 - 请参阅下面的codepen我的答案 – Johannes