【发布时间】:2018-03-28 13:49:38
【问题描述】:
我正在尝试将包含在显示设置为表格的 div 中的图像居中。在其中,我希望显示一个图像,它应该位于垂直和水平的中心。我已经使用 margin:auto 实现了水平位置并将其设置为 display: table-cell,但它没有垂直居中。任何帮助都会很棒
.overlay { height: 50%; background: red;position: fixed;
top: 0;
left: 0;
height: 50%;
width: 100%;
display: table;}
.swipe {height: 80px;
display: table-cell;
margin: auto;}
<div style="height:300px">
<div class="overlay">
<img class="swipe" src="https://d30y9cdsu7xlg0.cloudfront.net/png/255751-200.png" />
【问题讨论】: