css实现高度自适应正方形

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<style type="text/css">
    .div{
        background: red;
        width: 20%;
        overflow: hidden;
    }
    .div:after{
        content: '';
        display: block;
        margin-top: 100%;
    }
</style>
<body>
    <div class="div"></div>
</body>
</html>

猜你喜欢

转载自blog.51cto.com/12173069/2299007