I need to create a DIV where width=height, and height=100% of the viewport (which, obviously, is variable).
In other words, a perfectly sq
For those who may be looking for a pure CSS way to contain a square div with the maximum dimensions:
The key takeaway here is that you set
max-widthandmax-heightwhile settingwidthandheightto the opposite values.
HTML
CSS
html, body {
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
div {
background-color: red;
width: 100vh;
height: 100vw;
max-width: 100vw;
max-height: 100vh;
}
Live running example: https://jsfiddle.net/resistdesign/szrv5o19/