简体   繁体   中英

CSS Working in Chrome but not Firefox ( div height )

I have been building a website and mainly testing it in Chrome. Recently I realised some of the CSS does not apply in Firefox.

I guess it's probably : main { min-height }

This jFiddle reproduces this error, where the main div doesn't have the height it's supposed to. http://jsfiddle.net/msW9m/

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 :

#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% . 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%?
In some browsers, the body element doesn't keep 100% height until its content is full.

http://jsfiddle.net/HRKRN/

html, body {
    height: 100%;
}

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

use CSS3 to solve this issue

http://pastebin.com/Q8727Kvt

Align vertically using CSS 3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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