Html 将向量img居中放置在响应div框中?
我有一个向量img,它以正确的尺寸显示在一个使用css的响应div框中:Html 将向量img居中放置在响应div框中?,html,css,image,responsive-design,center,Html,Css,Image,Responsive Design,Center,我有一个向量img,它以正确的尺寸显示在一个使用css的响应div框中: .col1 > div { width:100%; height:25%; position: relative; } .thisIMGcontainer { height: 100%; width: 100%; position: absolute; display: table; } .thisIMG { background-image: url('../img/thisIMG.
.col1 > div {
width:100%;
height:25%;
position: relative;
}
.thisIMGcontainer {
height: 100%;
width: 100%;
position: absolute;
display: table;
}
.thisIMG {
background-image: url('../img/thisIMG.png');
background-size: contain;
background-repeat: no-repeat;
}
对于此HTML:
<div class="col1">
<div class="box1">
<div class="thisIMGcontainer"><div class="thisIMG"></div></div>
</div><!--/box1-->
</div>
我尝试了多种CSS组合,以使img在中心对齐,但它要么保持左对齐,要么随机消失
显示:表格标题;或显示:内联块;和保证金:0自动
您的图像div没有宽度,因此它占用所有可用宽度-100%。如果希望图像居中,则必须使用
标记而不是背景图像,或者必须在.thisIMG
类中设置宽度 顺便说一句,PNG不是矢量图像。@AndreiVolgin谢谢你指出这一点。。什么格式?谢谢你的提示。。甚至删除所有css,只需填充div框,只显示图像的上半部分?您根本不需要。这个imgcontainer
div。