Adam Khoury

Donate funds to show love and support

Click the button below to donate funds securely online. You can use your PayPal account or a credit card.

Your donations help free up my time to produce more content and assist in covering server costs. It's also a great way to say thanks for the content!

Application Configuration

Adam will be adding options here soon.

Window Size Responsive CSS Layout Stylesheet Change Tutorial

Published :
Author :
Adam Khoury
Learn to program layout responses to the browser window size changes using JavaScript to affect the CSS style sheet link element in the document. The script also handles layout adjustment when the document is initially loading. <!DOCTYPE html> <html> <head> <link id="pagestyle" rel="stylesheet" type="text/css" href="large.css"> <script> function layoutHandler(){ var styleLink = document.getElementById("pagestyle"); if(window.innerWidth < 900){ styleLink.setAttribute("href", "mobile.css"); } else if(window.innerWidth < 1200){ styleLink.setAttribute("href", "medium.css"); } else { styleLink.setAttribute("href", "large.css"); } } window.onresize = layoutHandler; layoutHandler(); </script> </head> <body> <div id="my_header"></div> <div id="my_menu"> <a href="#">Home</a> <a href="#">Services</a> <a href="#">Staff</a> <a href="#">Contact</a> </div> <div id="my_content"> Lorem ipsum goes here as dummy text, lots of it. </div> </body> </html>