css 边距和填充区别,边距和填充之间的区别?

b10eN.jpg

Margin是CSS中的属性,用于在边框之外的元素周围创建空间。程序员可以为顶部,右侧,底部和左侧设置边距。换句话说,他可以使用margin-top,margin-right,margin-bottom和margin-left来设置这些值。

该保证金值可以是以下类型的。

First, auto allows the browser to calculate the margin. Moreover, length denotes a margin in px, pt or cm, while % helps to describe a margin as a percentage relative to the width of the containing element. Finally, inherit denotes that the margin has to inherit from the parent element.

Padding is a property in CSS that helps to create space around an element inside the border. The programmer can set the padding for top, right, bottom and left. In other words, he can set those values using padding-top, padding-right, padding-bottom and padding-left.

The Padding values can be of the following types.

The length describes padding in px, pt or cm, while % denotes padding as a percentage relative to the width of the containing element. Finally, inherit describes that the padding should be inherited from the parent element.

div.special {

width:200px;

border-style: solid;

border-width:thin;

border-color:#000;

margin:30px 20px 10px 25px;

}

div.special2 {

width:200px;

border-style: solid;

border-width:thin;

border-color:#000;

padding:30px 20px 10px 25px;

}

Hello its margin test

Hello its padding test

Difference Between Margin and Padding

Margin is a CSS property that is used to create space around the element outside the defined border, while the padding is a CSS property that is used to create space around the element, inside the defined border. Thus, this explains the main difference between margin and padding.

Values

Furthermore, the values of margin can be auto, length, % or inherit, whereas the values of padding can be length, % or inherit type. Hence, this is another difference between margin and padding.

简而言之,margin和padding是CSS中的两个属性,可用于设置网页样式。无法为这些属性分配负值。边距和填充之间的主要区别在于,边距有助于在边框外部的元素周围创建空间,而填充有助于在边框内部的元素周围创建空间。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值