寬度自適應,高度是寬度的2倍
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.content {
background: lightblue;
width: 100%;
height: 0;
padding-bottom: 200%;
}
.container {
width: 200px;
}
</style>
</head>
<body>
<div class="container">
<div class="content"></div>
</div>
</body>
</html>
複製程式碼
原理: padding、margin根據父元素的width計算百分比數值