Skip to content

Instantly share code, notes, and snippets.

@kurtschlatzer
Last active October 6, 2015 21:18
Show Gist options
  • Save kurtschlatzer/3054593 to your computer and use it in GitHub Desktop.
Save kurtschlatzer/3054593 to your computer and use it in GitHub Desktop.
Use this to view the current browser window viewport dimensions -- useful for responsive design prototyping and debugging. minimal CSS absolute-positioned indicator box for height / width in pixels. Changes on resize.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Document Dimension Indicator</title>
<style type="text/css">
#dimbox {
position: absolute;
top: 5px; right: 5px;
z-index: 999;
background-color: #777777;
margin: 0; padding:5px 6px 3px;
font-size: .8em;
line-height: 1.2;
color: #cccccc;
}
#width, #height {
color: #ffffff;
font-size: 1.2em;
}
</style>
</head>
<body>
<p>This is a simple example to create a "live" width and height indicator that updates as you scale your page. I use it when testing responsive designs. For better efficiency, create a single .js file and include it at the end of your document -- commenting it out when you're done testing.</p>
<div id="dimbox">
Wpx&nbsp;<span id="width"></span>&nbsp;&nbsp;Hpx&nbsp;<span id="height"></span>
</div>
<script> // must be included after #dimbox
function widthGrabber() {
document.getElementById("width").innerHTML = window.innerWidth;
}
widthGrabber();
window.addEventListener( "resize", widthGrabber );
function heightGrabber() {
document.getElementById("height").innerHTML = window.innerHeight;
}
heightGrabber();
window.addEventListener( "resize", heightGrabber );
</script>
</body>
</html>
@kurtschlatzer
Copy link
Author

This is a simple example to create a "live" width and height indicator that updates as you scale your page. I use it when testing responsive designs. For better efficiency, create a single .js file and include it at the end of your document -- commenting it out when you're done testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment