CSS 居中 div 在 Firefox 中不居中

CSS centered div isn't centered in Firefox

我居中的 div 框,其中有一个图像并以 CSS 居中,在 Firefox 上看起来真的很糟糕!不知何故它被抵消了,如果这有意义的话?

它在 Safari 和 Chrome 中看起来都不错,我真的很想在 FF 中也能正确使用它。这是我的 CSS 位:

body {
  color: #000;
  font-size: 12px;
  line-height: 14px;
  font-family: Arial;
  font-weight: ;
  text-align: left;
  margin: 5% 0px 0px 0px;
  padding: 0px 0px 0px 0px;
}
div#mainimg {
  position: fixed;
  bottom: 50%;
  left: 0px;
  width: 100%;
  padding: 0px;
  z-index: 2;
}
.centeredmainimg {
  position: absolute;
  margin: auto;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}
<div id="mainimg">
  <img class="centeredmainimg" src="http://carriejade.com/images/name.png" />
</div>

我的意思是无论屏幕分辨率(和浏览器,可惜)如何,都让所有内容(我的名字图片 + 洋红色线)居中。

我在 firefox 中使用了这段代码,它运行良好(即使在 chrome 中):

position: fixed;
margin: auto;
left: 0px;
right: 0px;
top: 0px;
bottom: 0px;

您设置布局的方式有点乱七八糟,所以我最终不得不更正您网站上的大部分 style2.css。您可以使用 css display:flexflex-flow: row;justify-content 来实现相同的布局,而无需在每个元素上自定义定位。这解决了您遇到的居中问题。

/* CSS Document */
html, body {
    margin: 0px;
    padding: 0px;
    height: 100%;
}
body {
    display: flex;
    flex-flow: column;
    justify-content: space-between;
    font-size: 0;
}
body * {
    font-size: 12pt;
    line-height: 14pt;
    font-family: Arial;
    color: #000;
}
div#topdiv {
    height:40px;
    line-height:40px;
    font-family: "Courier New", Courier, monospace;
    font-size: 24px;
    background:#fff45f;
    text-align:center;
    z-index: 2;
}
div#bottomdiv {
    height:30px;
    font-family: 'Oswald', "Courier New", Courier, monospace;
    font-size: 20px;
    line-height: 30px;
    background:#ec008c;
    text-align:justify;
    z-index: 2;    
}
div#middlediv {
    line-height:10px;
    background:#ec008c;
}
div#mainimg {
    position:absolute;
    bottom:30px;
    top: 40px;
    left:0px;
    right: 0px;    
    z-index: 2;
}
.centeredmainimg {
    height: 100%;
    width: 100%; 
}