<!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>等宽高比</title>
<style>
.box {
width: 500px;
background: #333;
color: #fff;
}
.box::before {
content: '';
padding-top: 100%;
float: left;
}
.box::after {
content: '';
display: block;
clear: both;
}
</style>
</head>
<body>
<div class="box">给定可变宽度的元素,它将确保其高度以响应的方式保持成比例(即,其宽度与高度的比率保持恒定)。</div>
</body>
</html>
网友评论