【发布时间】:2019-04-02 03:02:59
【问题描述】:
我有一个这样的场景,我想要一个宽度为 100% 的图像作为背景。接下来我想在图像中间对齐两列布局文本。我使用显示表格单元格和垂直对齐:中间,它没有按预期工作。
预期的结果是两列布局在中间。 注意:图片必须作为背景,宽度为 100%,高度根据浏览器宽度缩放。
* {
margin: 0;
padding: 0;
}
<div style="position: relative;">
<img src="https://www.math.nmsu.edu/~pmorandi/math112f00/graphics/rectangle.gif" style="width: 100%; line-height: 0;" />
<div style="position: absolute; top: 0; left: 0; right: 0; bottom: 0;">
<div style="display: table; vertical-align: middle; padding-top: 100px;">
<div style="display: table-cell; width: 120px;">
Left Column
</div>
<div style="display: table-cell;">
<p>
Right Column Top
</p>
<p>
Right Column Bottom
</p>
</div>
</div>
</div>
</div>
【问题讨论】:
-
您想将表格水平居中还是垂直居中?
-
@LucaJung 是的,如果你能证明如何同时实现这两个目标,那就太好了
-
@vincentsty 使用
table和flexbox显示查看我的解决方案,让我知道您的反馈。谢谢!
标签: html css css-tables