css样式中margin的使用

概念

css样式中margin属性的使用;

描述
auto浏览器计算外边距
length自定义固定外边距(单位:像素、厘米)
%以父级元素宽度的百分比指定外边距
inherit继承父级元素的外边距属性

栗子

1、length使用:

html:

	<div class="container">
      <div class="box-a">
        <div class="box-a-a"></div>
      </div>
    </div>

css:

	 .container {
        width: 100%;
        height: 600px;
      }
      .box-a {
        width: 400px;
        height: 500px;
        border: 2px solid red;
      }

      .box-a-a {
        width: 100%;
        height: 250px;
        background-color: pink;
        margin-top: 200px;
      }

效果图:
在这里插入图片描述

% 的使用:

注意:% 是基于父容器的 宽度 设定外边框

html:

	<div class="container">
      <div class="box-a">
        <div class="box-a-a"></div>
      </div>
    </div>

CSS:

      .container {
        width: 100%;
        height: 600px;
        display: flex;
        justify-content: center;
        align-items: center;
      }
      .box-a {
        width: 400px;
        height: 500px;
        border: 2px solid red;
      }

      .box-a-a {
        width: 100%;
        height: 250px;
        background-color: pink;
        margin-top: 100%;
      }

效果图:
在这里插入图片描述

inherit 的使用

这个…好像不能继承父级margin,如有其他想法请评论留言一块交流交流。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值