Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 将向量img居中放置在响应div框中?_Html_Css_Image_Responsive Design_Center - Fatal编程技术网

Html 将向量img居中放置在响应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.

我有一个向量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.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。