溫馨提示×

css中margin屬性的意義是什么

清風(fēng)
300
2021-03-11 08:22:02
欄目: 編程語言

css中margin屬性的意義是什么

css中margin屬性的意義是外邊距間隔屬性,可以通過它來實(shí)現(xiàn)兩個(gè)div之間的間距。

示例:

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>水平方向的兩個(gè)盒子</title>

    <style>

        *{

            margin:0;

            padding:0;

            border:0;

        }

        body{

            font-size: 0;

        }

        .left{

            width: 100px;

            height: 100px;

            background: red;

            display: inline-block;

            margin-right: 50px;

            font-size: 20px;

        }

        .right{

            width: 100px;

            height: 100px;

            background: yellow;

            display: inline-block;

            margin-left: 50px;

            font-size: 20px;

        }

    </style>

</head>

<body>

    <div>寬為100px,右邊距為50px</div>

    <div>寬為100px,左邊距為50px</div>

</body>

</html>


0