bootstrap4 调整元素之间距离

影响元素之间的间距是可以通过stylemarginpadding属性来实现,但这两个属性本意并不相同;
margin影响的是本元素与相邻外界元素之间的距离,这里简称外边距;
padding影响的元素本身与其内部子元素之间的距离,简称为内填充。

bootstrap4提供了简写的class名,名称分别以m-开头和p-开头的类。

一、影响距离大小的值有

0,1,2,3,4,5,auto

(1)、margin值有

class名等价的style
m-0等价于{margin:0 !important}
m-1等价于{margin:0.25rem !important}
m-2等价于{margin:0.5rem !important}
m-3等价于{margin:1rem !important}
m-4等价于{margin:1.5rem !important}
m-5等价于{margin:3rem !important}
m-auto等价于{margin:auto !important}

(2)、padding值有

class名等价的style
p-0等价于{padding:0 !important}
p-1等价于{padding:0.25rem !important}
p-2等价于{padding:0.5rem !important}
p-3等价于{padding:1rem !important}
p-4等价于{padding:1.5rem !important}
p-5等价于{padding:3rem !important}
p-auto等价于{padding:auto !important}

二、调整某一侧的边距

有几个缩写,t,b,l,r,x,y含义分别是top,bottom,left,right,leftright,topbottom

(1)、margin例子,距离大小可以0-5auto,这里只用期中一个值来说明含义

class名等价的style
mt-2{margin-top: 0.5rem !important}
mb-2{margin-bottom: 0.5rem !important}
ml-2{margin-left: 0.5rem !important}
mr-2{margin-right: 0.5rem !important}
mx-2{margin-right: 0.5rem !important;margin-left: 0.5rem !important}
my-2{margin-top: 0.5rem !important;margin-bottom: 0.5rem !important}

(2)padding例子

class名等价的style
pt-2{padding-top: 0.5rem !important}
pb-2{padding-bottom: 0.5rem !important}
pl-2{padding-left: 0.5rem !important}
pr-2{padding-right: 0.5rem !important}
px-2{padding-right: 0.5rem !important;margin-left: 0.5rem !important}
py-2{padding-top: 0.5rem !important;margin-bottom: 0.5rem !important}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值