[英]Why does Google Chrome ignore “top” css property in a relatively-positioned element inside a flex-box?
[英]how to vertically center an image inside of a relatively-positioned container?
我想在下面的HTML中垂直居中图像,使它垂直居中于它旁边的div(“rtUpdateContentDiv”)。 img和div都在父容器“rtUpdateContainerDivActive”中。
<div class="rtUpdateContainerDivActive">
<img class="statusImg" src="images/icons/Knob-Valid-Green.png">
<div class="rtUpdateContentDiv">
<span class="rtBlueHighlight">date and time:</span>
ipsum lorem text here
</div>
</div>
这是目前为止的图像的CSS:
.statusImg
{
position: absolute;
margin-top: auto;
margin-bottom: auto;
vertical-align: middle;
padding-left: 3px;
padding-top: 3px;
}
和容器:
.rtUpdateContainerDivActive
{
background-color: #90ee90;
margin-top: 1%;
position: relative;
min-height: 38px;
}
父母需要保持亲戚关系。
如何垂直居中图像(38px x 38px)?
感谢您的任何帮助!
解决方法1:
.parent{
display: inline-table;
height:100%;
}
.middleChild{
display: table-cell;
vertical-align: middle;
}
溶液2:
.statusImg
{
position: absolute;
height:38px;
top:50%;
margin-top:-19px;
}
希望它会有所帮助......
您可能希望阅读此http://css-tricks.com/centering-in-the-unknown/ ,最后一种方法可能是您需要的方法。
使用top: 50%
用组合的margin-top
一半的图像高度的: http://jsbin.com/adiseq/1/edit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.