[CSS] aspect-ratio
Browser support: https://caniuse.com/?search=aspect-ratio
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.box1 {
width: 50%;
background-color: red;
aspect-ratio: 1;
}
.box2 {
width: 50%;
background-color: blue;
aspect-ratio: 4/3;
}
.box3 {
width: 50%;
background-color: green;
aspect-ratio: 16/9;
}
</style>
</head>
<body>
<h2>aspect-ratio (横纵比)</h2>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
</body>
</html>