I saw a solution for height depending on width: css height is the same as width . Or here: https://stackoverflow.com> But my question is the opposite.
My item:
<body> <div id="square"></div> </body>
Style for him:
body, html { margin: 0; height: 100%; min-height: 300px; position: relative; } div#square { height: 75%; width: 75vh; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background-color: darkorange; }
Script that saves it squared:
window.onload = window.onresize = function (event) { var mySquare = document.getElementById("square"); mySquare.style.width = mySquare.offsetHeight + 'px'; };
Full code here: http://jsfiddle.net/je1h/hxkgfr9g/
The question is to do the same in pure CSS. There are no scripts.
css aspect-ratio
jevgenij
source share