css3标准盒模型和怪异(IE)盒模型

前端和盒模型包括两种 分别是W3c盒模型和IE盒模型

W3C盒模型包括content、padding、border、margin 其中width = content

IE盒模型包括content、padding、border、margin 其中width = content+padding+border

在之后后来W3C在CSS3中新增了box-sizing的样式 属性包含content-box和border-box也就是box-sizing:content-box就是默认(在设置时候)的样式(W3C盒模型)box-sizing: border-box(IE盒模型)是width包含了content+padding+boder。

(1)标准盒模型 content-box 元素的总宽度width=content+padding+border

<template>
<!-- 标准盒模型 -->
  <div class="box">
    123
  </div>
  <!-- border  padding width  100+20+10 = 130-->
</template>


<style scoped>
.box{
  width: 100px;
  height: 100px;
  border: 10px solid red;
  padding: 5px;
}
</style>

在这里插入图片描述    在这里插入图片描述
实际元素的宽度为:width=100+20+10 = 130
实际元素的高度为:height=100+20+10 = 130

(2)IE怪异盒模型 box-sizing: border-box 元素的总宽度width=width(用样式指定的宽度)

context=设置是元素宽度-border-padding

<template>
	<!-- 怪异盒模型 -->
  	<div class="box">
    	123
  	</div>
</template>

<style scoped>
.box{
  width: 200px;
  height: 200px;
  border: 5px solid red;
  padding: 10px;
  //设置怪异盒模型加这个
  box-sizing: border-box;
}
</style>

在这里插入图片描述   在这里插入图片描述
实际元素的宽度为:width=200
实际元素的高度为:height=200

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值