简体   繁体   English

CSS在Chrome中工作但不在Firefox中工作(div高度)

[英]CSS Working in Chrome but not Firefox ( div height )

I have been building a website and mainly testing it in Chrome. 我一直在建立一个网站,主要是在Chrome中测试它。 Recently I realised some of the CSS does not apply in Firefox. 最近我意识到一些CSS不适用于Firefox。

I guess it's probably : main { min-height } 我想这可能是:主{min-height}

This jFiddle reproduces this error, where the main div doesn't have the height it's supposed to. 这个jFiddle再现了这个错误,其中主div没有它应该具有的高度。 http://jsfiddle.net/msW9m/ http://jsfiddle.net/msW9m/

HTML : HTML:

<div id='main'></div>
<div id="container"></div>
<div id='footer'>
    <div id='footerRelative'>Development by <a href='mailto:'>John Doe</a></div>
</div>​

CSS : CSS:

#main {
    min-height: 80%;
    height: auto;
    border: 1px solid #bbbbbb;
    margin: 3% 5% 1%;
    padding: 10px 10px;
}
#footer {
    position: absolute;
    left: 50%;
}
#footerRelative {
    position: relative;
    left: -50%;
    font-size: 80%;
}
/*Probably Irrelevant*/
#container {
    margin: 0 auto;
    margin-top: -300px;
    margin-left: -261px;
    position: absolute;
    top: 50%;
    left: 50%;
    width: 523px;
    height: 600px;
    background-image: url('../images/doctorSymbol.jpg');
    background-repeat:no-repeat;
    background-position:center;
    opacity: 0.125;
    overflow: hidden;
    z-index: -1;
}

However, in Chrome everything works perfectly and the main div has a min-height of 80% . 但是,在Chrome中,一切都很完美,主div的最小高度为80%。 I was wondering if there is a workaround to this or If I am doing something wrong. 我想知道是否有解决方法,或者我做错了什么。

Thank you. 谢谢。

Have you tried making body and html 100%? 你有没有试过制作身体和HTML 100%?
In some browsers, the body element doesn't keep 100% height until its content is full. 在某些浏览器中,body元素在其内容已满之前不会保持100%的高度。

http://jsfiddle.net/HRKRN/ http://jsfiddle.net/HRKRN/

html, body {
    height: 100%;
}

也是一个可行的解决方案:将div的显示设置为table-cell

use CSS3 to solve this issue 使用CSS3来解决这个问题

http://pastebin.com/Q8727Kvt

Align vertically using CSS 3 使用CSS 3垂直对齐

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM