CSS square with dynamic height
问题 I need to make a div square. The height of the div is dynamically changing and I want the width to be equal to the height. I have seen a lot of solutions to set the height to be equal to the width (with padding-bottom on pseudo-elements), but I need it the other way arround. Is this possible with pure CSS? 回答1: No .... well, there is this trick, where one use a hidden image div { display: inline-block; height: 170px; background: red; } div img { visibility: hidden; height: 100%; } <div> <img