我知道 margin-left:auto;
和 margin-right:auto;
使元素居中为 text-align:center;
确实如此。
我的问题是关于垂直对齐。
我想让我的图像与我的 vh 相关。
<section>
<div class="half">
<img />
</div>
<div class="half">
<img />
</div>
</section>
风格:
.half {
height:100%;
width: 50%;
display:inline-block;
float:left;
}
.half img {
max-width:93%;
max-height:90%;
}
Fiddle 上的一个例子: http://jsfiddle.net/f16wpgpm/3/
最佳答案
将 position:relative;
添加到 .half
,然后将以下 CSS 添加到您的 img
选择器:
margin: auto;
left: 0;
right: 0;
top: 0;
bottom: 0;
Updated Fiddle
关于html - 如何在响应式布局中垂直对齐图像而无需绝对定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27385944/