如果我理解正确,你正在尝试垂直对齐一个div,你必须在它的图像另一个DIV。
垂直对齐div的最佳方法是将图像作为背景图像,并为该div设置一个高度,这将阻止高度变为动态&它为您提供更多控制。例如;
<!-- Div with BG Image -->
<div class="col-sm-4 col-md-4">
<div class="bg-image" style="background-image:url(/img/height.svg);"></div>
</div>
.bg-image {
background-repeat: no-repeat;
background-position: top center;
background-size: cover;
height: 250px; // this can be anything
}
<!-- Div to be centrally aligned -->
<div class="col-sm-4 col-md-4">
<div class="bg-image-module">
<div class="bg-image-module-block">
<span>Height</span><br/>335.00 mm
</div>
</div>
</div>
Give the bg-image-module div these styles:
.bg-image-module {
display: table;
height: 250px; //this must be the same as the height on the bg-image div in order to vertically align the content.
}
.bg-image-module-block {
display: table-cell;
vertical-align: middle;
}
这是垂直对齐内容的好方法,你可以改变的高度是你需要什么,它可以响应改变。
添加您当前的CSS代码段 –
目前我想了很多的资源我互联网上找到,但他们没有帮助,因此可以说的CSS是自举默认的:) – Troyer
你试试这个:''
– Banzay