img绝对定位在div中间,img上下稍微移动问题

问题展示:

div{

  position: relative;

  width:100px;

  height:100px;

}

div>img{

  position: absolute!important;

  width: 100%;

  left: 50%;

  top: 50%;

  transform: translateY(-50%,-50%);

  -webkit-transform:translate(-50%,-50%);

  -moz-transform: translate(-50%,-50%);

  -ms-transform: translate(-50%,-50%);

  -o-transform: translate(-50%,-50%);

  display: block;

}

在chrome是不会抖动,但是在搜狗浏览器上图片会上下抖动

解决方法:

div>img{

  position: absolute!important;

  width: 100%;

  left: 0;

  top: 0;

  right:0;

  bottom:0;

  margin:auto;

  display: block;

}

猜你喜欢

转载自www.cnblogs.com/yuan-luo/p/9023592.html
IMG