【Bootstrap Learning】-5 Spacing

本文介绍了Bootstrap中的间距类(Spacing)使用,包括设置margin和padding的大小,如m-5, ml-5, ml-md-5等,以及如何实现元素的水平居中和使用负margin。" 113985501,10296947,Python坐标轴设置与操作详解,"['Python开发', '数据可视化', 'matplotlib']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 选择 Documentation -- 选择Utilities -- Spacing

 2. margin 和 padding   

    Where property is one of:

  • m - for classes that set margin
  • p - for classes that set padding

   Where sides is one of:

  • t - for classes that set margin-top or padding-top
  • b - for classes that set margin-bottom or padding-bottom
  • l - for classes that set margin-left or padding-left
  • r - for classes that set margin-right or padding-right
  • x - for classes that set both *-left and *-right
  • y - for classes that set both *-top and *-bottom
  • blank - for classes that set a margin or padding on all 4 sides of the element

    Where size is one of:

  • 0 - for classes that eliminate the margin or padding by setting it to 0
  • 1 - (by default) for classes that set the margin or padding to $spacer * .25
  • 2 - (by default) for classes that set the margin or padding to $spacer * .5
  • 3 - (by default) for classes that set the margin or padding to $spacer
  • 4 - (by default) for classes that set the margin or padding to $spacer * 1.5
  • 5 - (by default) for classes that set the margin or padding to $spacer * 3
  • auto - for classes that set the margin to auto

 

<div class="container">
    <div class="bg-danger  m-5">I am simple div</div>
    <div class="bg-success m-4">I am simple div</div>
    <div class="bg-info m-3">I am simple div</div>
    <div class="bg-warning m-2">I am simple div</div>
    <div class="bg-primary m-1">I am simple div</div>
    <div class="bg-secondary m-0">I am simple div</div>
    <div class="bg-dark text-light m-0">I am simple div</div>
</div>
<br>
<br>
<br>
<div class="container">
    <div class="bg-danger  p-5">I am simple div</div>
    <div class="bg-success p-4">I am simple div</div>
    <div class="bg-info p-3">I am simple div</div>
    <div class="bg-warning p-2">I am simple div</div>
    <div class="bg-primary p-1">I am simple div</div>
    <div class="bg-secondary p-0">I am simple div</div>
    <div class="bg-dark text-light p-0">I am simple div</div>
</div>


<div class="container">
    <div class="bg-danger  ml-5 ml-md-5">I am simple div</div>
    <div class="bg-success mt-4 mt-lg-5">I am simple div</div>
    <div class="bg-info mb-3 mb-sm-5" >I am simple div</div>
    <div class="bg-warning mr-2">I am simple div</div>
    <div class="bg-primary m-1">I am simple div</div>
    <div class="bg-secondary m-0">I am simple div</div>
    <div class="bg-dark text-light m-0">I am simple div</div>
</div>

 m-5 

 ml-5

 ml-md-5

DIV水平居中

<div class="container">
    <div class="bg-danger  mx-auto w-25 text-center">I am simple div</div>
</div>

负margin(有负的margin,没有负的padding)  

<div class="row mx-md-n5 ">
    <div class="col px-md-5">
        <div class="p-3 border bg-light">Custom column padding</div>
    </div>
    <div class="col px-md-5">
        <div class="p-3 border bg-light">Custom column padding</div>
    </div>
  </div>

   mx-n5 mx-md-n5

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值