Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
949 views
in Technique[技术] by (71.8m points)

css - whitespace out of html body

I have a very annoying html/css design-bug:

I want to have a footer with a height of 25px, which always stays on the bottom of the site.

The site should always consume 100% of the browser's screen, and must not display scrollbars.

Here's a simplified version of the html, which causes the bug:

<body>
    <div id="content">foo</div>
    <div id="tools">    
        <img src="img/save.png" alt="save file"/>
        <img src="img/save.png" alt="save file"/>
    </div>
</body>

The css:

*{
    padding: 0;
    margin: 0;
}

body, html{
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

#content{
    background-color: #bbb;
    height: calc(100% - 25px);
}

#tools{
    height: 25px;
    background-color: #ddd;
}

#tools img{
    height: 100%;
}

The footer always uses 25px of height, the content-div above consumes the rest.

However, I get an additional whitespace of 4px below the footer, which leads the vertical scrollbar to appear:

screenshot

This appears in all Browsers (Chrome, Firefox, IE, Opera), so it must be my fault. When I remove the image-element, the space disappears.

What causes this problem and how can I avoid it?

Note that overflow: hidden; in the body-element is not an option.

Here's a JSFiddle

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this code

DEMO

#tools img{
    vertical-align:bottom;
    height: 100%;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...