css的box模型_CSS Box模型

css的box模型

Every CSS element is essentially a box. Every element is a generic box.

每个CSS元素本质上都是一个盒子。 每个元素都是一个通用框。

The box model explains the sizing of the elements based on a few CSS properties.

盒子模型基于一些CSS属性说明了元素的大小。

From the inside to the outside, we have:

从内到外,我们有:

  • the content area

    内容区域
  • padding

    填充
  • border

    边境
  • margin

    保证金

The best way to visualize the box model is to open the browser DevTools and check how it is displayed:

可视化盒子模型的最佳方法是打开浏览器DevTools并检查其显示方式:

Here you can see how Firefox tells me the properties of a span element I highlighted. I right-clicked on it, pressed Inspect Element, and went to the Layout panel of the DevTools.

在这里,您可以看到Firefox如何告诉我突出显示的span元素的属性。 我右键单击它,按Inspect Element,然后转到DevTools的“布局”面板。

See, the light blue space is the content area. Surrounding it there is the padding, then the border and finally the margin.

看到,浅蓝色空间是内容区域。 围绕它的是填充,然后是边框,最后是边距。

By default, if you set a width (or height) on the element, that is going to be applied to the content area. All the padding, border, and margin calculations are done outside of the value, so you have to take this in mind when you do your calculation.

默认情况下,如果您在元素上设置宽度(或高度),则该宽度(或高度)将应用于内容区域 。 所有的填充,边框和边距计算都在值之外进行,因此在进行计算时必须牢记这一点。

You can change this behavior using Box Sizing.

您可以使用Box Sizing更改此行为。

翻译自: https://flaviocopes.com/css-box-model/

css的box模型

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值