什么是盒子模型中的外边距

目录

外边距:

margin的简写属性:


外边距:

外边距在外边所以就不会影响盒子的大小,但是会影响到盒子的位置

一共有四个方向的外边距

margin-top:

                        上外边距,设置一个正值,元素会向下移动

margin-right:

                        默认情况下设置margin-right不会产生任何的效果

margin-bottom:

                        下外边距,设置一个正值,其下边的元素会向下移动

margin-left:

                        上左边距,设置一个正值,元素会向右移动

元素在页面中是按照自左向右的顺序排列的,

所以默认情况下如果我们设置的左和上外边距则会移动自身,

而设置下和右外边距会移动其他元素

<!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>Document</title>
    <style>
        .box{
            background-color: black;
            width: 200px;
            height: 200px;
            border: 20px orange solid;
            padding: 20px;
            margin-top: 100px;
            margin-left: 100px;
        }
        .abc{
            background-color: aqua;
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="abc">sbv</div>
    </div>

</body>
</html>

 设置下和右外边距会移动其他元素

<!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>Document</title>
    <style>
        .box{
            background-color: black;
            width: 200px;
            height: 200px;
            border: 20px orange solid;
            padding: 20px;
            margin-top: 100px;
            margin-left: 100px;
            margin-bottom: 200px;
            /*
            这里的margin-bottom就是移动的其他元素
            */
        }
        .abc{
            background-color: aqua;
            width: 100%;
            height: 100%;
        }
        .hb{
            width: 200px;
            height: 200px;
            border: 20px;
            background-color: black;
            margin-left: 200px;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="abc">sbv</div>
    </div>
    <div class="hb"> </div>
</body>
</html>

 margin也可以设置负值,如果是负值,则元素会向相反的方向移动(负值就相当于减少位置的像素,所以会向相反的方向移动)

margin的简写属性:

margin可以同时设置四个方向的外边框,用法和padding 一样

margin虽然不会改变可见框的大小,但是会影响到盒子实际的占用空间

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

翘指

创作不易,一分也是爱

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值