简体   繁体   中英

Fullscreen HTML Element using window.innerHeight/Width different with DOCTYPE

I'm trying to make an HTML5 canvas element fullscreen with the window.innerHeight and innerWidth properties.

Unfortunately, on Chrome 10, when I set use the following doctype:

<!DOCTYPE HTML>

...there is some extra scrolling space indicated by scroll bars which shouldn't appear.

Without a doctype, everything is fine.

The element is an HTML5 canvas, so styling with 100% will only stretch the content.

Is it worth using a doctype which breaks my functionality (without which might be bad?), or should I subtract, say, 15px from the values in order to keep scroll bars from appearing? (which is kludgy)

It is surely because of the default padding found on the body element of the page. Remove all default padding and margins using:

* {
    padding: 0;
    margin: 0;
}

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