css 外边距,内边距

外边距

外边距属性可以定义元素周围的空间,没有颜色,是透明的。

属性说明
margin-bottom设置元素的下边距
margin-top设置元素的上边距
margin-left设置元素的左边距
margin-right设置元素的左边距

组合属性

  1. margin: 10px 5px 3px 20px ;
    1. 上边距10px;
    2. 右边距5px;
    3. 下边距3px;
    4. 左边距20px;

  2. margin: 23px 43px 10px;

    1. 上边距23px;
    2. 左右边距43px;
    3. 下边距10px;
  3. margin: 20px 10px;

    1. 上下边距20px;
    2. 左右边距10px;
  4. margin: 20px;

    1. 上下左右20px;

示例:

<style>
    .div1 {
        width: 600px;
        height: 400px;
        color: rgb(100, 123, 255);
        outline: 2px solid red;
        text-align: center;
        line-height: 400px;
        overflow: hidden;
    }
    
    .div2 {
        width: 100px;
        height: 100px;
        background-color: rgb(123, 255, 248);
        margin-left: 250px;
        margin-top: 150px;
    }
</style>

<body>
    <div class="div1">
        <div class="div2">

        </div>
    </div>
</body>

div盒子移动

内边距

padding定义元素内容于边框的空间,也是没有颜色及透明。

属性说明
padding-bottom设置底部的内边距
padding-left设置左边的内边距
padding-top设置顶部的内边距
padding-right设置右边的内边距

组合属性

  1. padding:10px 20px 16px 20px;

    1. 上内边距10px;
    2. 右内边距20px;
    3. 下内边距16px;
    4. 左内边距20px;
  2. padding: 10px 23px 40px;
    1.上内边距10px;
    2. 左右内边距23px;
    3. 下内边距40px;

  3. padding: 12px 10px ;

    1. 上下内边距12px
    2. 左右内边距10px;
  4. padding: 20px;

    1.上下左右内边距20px;

<style>
    .div1 {
        width: 600px;
        height: 400px;
        background-color: rgb(255, 213, 213);
        color: rgb(100, 123, 255);
        text-align: center;
        /*下方的属性防止盒子撑大*/
        box-sizing: border-box;  
        padding-left: 100px;
        padding-top: 150px;
    }
</style>

<body>
    <div class="div1">
        学习前端知识
    </div>
</body>

padding变换

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值