The best way to do this with modern browsers would be to make use of Viewport-percentage Lengths, falling back to regular percentage lengths for browsers which do not support those units.
Viewport-percentage lengths are based upon the length of the viewport itself. The two units we will use here are vh
(viewport height) and vw
(viewport width). 100vh
is equal to 100% of the height of the viewport, and 100vw
is equal to 100% of the width of the viewport.
Assuming the following HTML:
<body>
<div></div>
</body>
You can use the following:
html, body, div {
/* Height and width fallback for older browsers. */
height: 100%;
width: 100%;
/* Set the height to match that of the viewport. */
height: 100vh;
/* Set the width to match that of the viewport. */
width: 100vw;
/* Remove any browser-default margins. */
margin: 0;
}
Here is a JSFiddle demo which shows the div
element filling both the height and width of the result frame. If you resize the result frame, the div
element resizes accordingly.