CSS盒子模型

 所有HTML元素可以看作盒子,在CSS中,"box model"这一术语是用来设计和布局时使用。
CSS盒模型本质上是一个盒子,封装周围的HTML元素,它包括:边距(margin),边框(border),填充(padding),和实际内容(content)

在这里插入图片描述

  • Margin(外边距) - 清除边框外的区域,外边距是透明的。
  • Border(边框) - 围绕在内边距和内容外的边框。
  • Padding(内边距) - 清除内容周围的区域,内边距是透明的。
  • Content(内容) - 盒子的内容,显示文本和图像。

在这里插入图片描述
代码:


<head>
  <meta charset="UTF-8">
  <style>
  .outerDiv {
  width: 800px;
  height: 300px;
  border: 1px solid green;
  background-color: rgb(230, 224, 224);
  margin: 0px auto;
  }
  .innerDiv{
  width: 100px;
  height: 100px;
  border: 1px solid blue;
  float: left;
  /* margin-top: 10px;
  margin-right: 20px;
  margin-bottom: 30px;
  margin-left: 40px; */
  margin: 10px 20px 30px 40px;
  }
  .d1{
  background-color: greenyellow;
  /* padding-top: 10px;
  padding-right: 20px;
  padding-bottom: 30px;
   padding-left: 40px; */
  padding: 10px 20px 30px 40px;
  }
  .d2{
  background-color: rgb(79, 230, 124);
  }
  .d3{
  background-color: rgb(26, 165, 208);
  }
  </style>
  </head>
  <body>
  <div class="outerDiv">
  <div class="innerDiv d1">框1</div>
  <div class="innerDiv d2">框2</div>
  <div class="innerDiv d3">框3</div>
  </div>
  </body>

效果;
在这里插入图片描述
在浏览器上,通过F12工具查看盒子模型状态


在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

StoicD

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值