Here is my attempt to achieve the ultimate goal.
The key point is to use vmin percentage of the viewport for the width and height properties of the square field:
Example here
.body, .square { display: flex; align-items: center; justify-content: center; } .body { min-height: 100vh; } .square { width: 100vmin; height: 100vmin; }
(vendor prefix omitted for brevity, check out Compiled Browsing in the demo).
source share