box-sizing: border-box

直接设置盒子整体大小包含边框在内

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .vv {
            width: 300px;
            height: 300px;
            background-color: pink;
            border: 20px solid green;
            margin-bottom: 10px;
            padding: 20px;
            box-sizing: border-box;
        }
        .yy {
            width: 300px;
            height: 300px;
            background-color: pink;
            border: 20px solid green;
            box-sizing: content-box;
            padding: 20px;
        }
    </style>
</head>
<body>
    <div class="vv">666666666666666666</div>
    <div class="yy">666666666666666666</div>
</body>
</html>

 

posted @ 2022-06-12 11:03  欧阳天天  阅读(66)  评论(0编辑  收藏  举报