function setSize(varWidth, varHeight){ var box = document.getElementById("webBoxSel"); var boxHeight = (varHeight / 2); var boxwidth = (varWidth / 2); if(boxHeight >= 300) { box.style.backgroundColor = 'red'; }else{ box.style.backgroundColor = 'yellow'; } box.style.width = boxwidth+'px'; box.style.height = boxHeight+'px'; var textInBox = document.getElementById("boxText"); textInBox.style.color = 'blue'; textInBox.style.margin = '25%'; textInBox.style.marginLeft = '25%'; } if(document.readyState === "loading"){ const varW = window.outerWidth; const varH = window.outerHeight; setSize(varW, varH); } window.addEventListener("resize", function (){ const varW = window.outerWidth; const varH = window.outerHeight; setSize(varW, varH); })