需要通过CSS将图像置于网页中心

Rob*_*bot 10 css image center

即使在调整浏览器大小时,我也希望将图像纵向和横向居中.

目前,我使用这个CSS:

.centeredImage {
  position: fixed;
  top: 50%;
  left: 50%;
  margin-top: -50px;
  margin-left: -150px;
}
Run Code Online (Sandbox Code Playgroud)

这个HTML:

<img class="centeredImage" src="images/logo.png">
Run Code Online (Sandbox Code Playgroud)

它以FF为中心但不是IE(图像中心位于左上角).有任何想法吗?

-机器人

Bab*_*dha 18

我这样解决了:

img.class-name{

    position: absolute;
    margin: auto;
    left: 0; 
    right: 0;
    top: 0;
    bottom: 0;  
}
Run Code Online (Sandbox Code Playgroud)


med*_*ium 7

试试这个:

position: absolute
Run Code Online (Sandbox Code Playgroud)