Click here to Skip to main content
15,892,697 members
Articles / Programming Languages / Javascript
Alternative
Tip/Trick

Set height of a div to full screen

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
23 Nov 2011CPOL 9.6K   1
blahhtml, body { height: 100%; width: 100%; padding: 0; margin: 0;}#derpy { height: 100%; width: 100%; background-color: #123456;} derpNo...
HTML
<!DOCTYPE html>
<html>
<head>
<title>blah</title>
<style type="text/css">
html, body {
  height: 100%;
  width: 100%;
  padding: 0;
  margin: 0;
}
#derpy {
  height: 100%;
  width: 100%;
  background-color: #123456;
}
</style>
</head>
<body>
  <div id="derpy">derp</div>
</body>
</html>

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.

License

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


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

Comments and Discussions

 
GeneralReason for my vote of 5 excelelnt alternative.. Accepting it... Pin
bbirajdar23-Nov-11 0:52
bbirajdar23-Nov-11 0:52 
Reason for my vote of 5
excelelnt alternative.. Accepting it without testing hoping it works

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.