css

40、怪异盒子

yu
yu
2024-09-30 / 0 评论 / 3 阅读 / 正在检测是否收录...

<!DOCTYPE html>
<html lang="en">
<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>怪异盒子的概念</title>
    <style>
        /*
            怪异盒子的宽度是加内边距和边框
            box-sizing
            可选值:
                content-box{默认值}
                border-box{挤压内部}

        */
        .box1{
            width: 200px;
            height: 200px;
            background-color: red;
            padding: 30px;
            border: 10px solid black;

            /*标准盒模型*/
            box-sizing: content-box;

        }
        .box2{
            width: 200px;
            height: 200px;
            background-color: green;
            margin-top: 100px;
            padding: 30px;
            border: 10px solid black;

            /*怪异盒模型*/
            box-sizing: border-box;
        }
    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
</body>
</html>
0

评论 (0)

取消