JSFiddle - React, Tailwind, and code Playground

HTML

<div id="div1">123</div>
<div id="div2">456</div>

CSS

#div1{
    background: red;
    position:absolute;
    height:100%;
    width:20px;
    top:0;
    left:0;
}
#div2{
    width:100%;
    height:500px;
    background-color:green;
    margin-left: 20px;
}

JavaScript

window.onresize = function(event) {
    winW = window.innerWidth;
    winH = window.innerHeight;   
    console.debug("x axis:" + winW  + "y axis:" + winH);
    
    if(winW < winH){
       var elem = document.getElementById('div1');
        
        console.debug("test" + elem.style.width);
        
       var a = elem.style.height;
       elem.style.height = elem.style.width;
       elem.style.width = a;
        
    }
    else{
       var elem = document.getElementById('div1');
        
        elem.style.height = elem.style.height;
        elem.style.width = elem.style.width;
    }
}