Click here to Skip to main content
13,457,828 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


Posted 22 Nov 2011

Set height of a div to full screen

, 23 Nov 2011
Rate this:
Please Sign up or sign in to vote.
blahhtml, body { height: 100%; width: 100%; padding: 0; margin: 0;}#derpy { height: 100%; width: 100%; background-color: #123456;} derpNo...
<!DOCTYPE html>
<style type="text/css">
html, body {
  height: 100%;
  width: 100%;
  padding: 0;
  margin: 0;
#derpy {
  height: 100%;
  width: 100%;
  background-color: #123456;
  <div id="derpy">derp</div>

No JavaScript was needed at all...

However, it is important to set the height of the body / HTML and to use a proper doctype to turn every browser into the "good" rendering mode.

Why have I set the padding and margin of the HTML and body to 0 is explained: some browsers would render this code without it with scrollbars where you can basicly scroll some pixel down and right.

I have lots of experience in writing dynamic resolution full window applications. That is where this experience comes from.

I successfully have tested this now in following browsers: Microsoft Internet Explorer 4.01 (4.72.3110.0), Mozilla Firefox 3.0.3 and most Major Browsers.

The fact alone that it runs in IE 4 should be proof enuf that this is a charm.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
Germany Germany
This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...


Comments and Discussions

GeneralReason for my vote of 5 excelelnt alternative.. Accepting it... Pin
B Birajdar23-Nov-11 0:52
memberB Birajdar23-Nov-11 0:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180323.1 | Last Updated 23 Nov 2011
Article Copyright 2011 by GottZ
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid