Can I give the col-md-1.5 in bootstrap?

前端 未结 11 1404
忘了有多久
忘了有多久 2020-12-07 22:08

I want to adjust the columns in Twitter Boοtstrap.

I know in bootstrap there are 12 columns grid. Is there any way to manipulate the grids to have 1.5 3.5 3.5 3.5 i

相关标签:
11条回答
  • 2020-12-07 22:11

    As others mentioned in Bootstrap 3, you can use nest/embed techniques.

    However it is becoming more obvious to use pretty awesome feature from Bootstrap 4 now. you simple have the option to use the col-{breakpoint}-auto classes (e.g. col-md-auto) to make columns size itself automatically based on the natural width of its content. check this for example

    0 讨论(0)
  • 2020-12-07 22:11

    Bootstrap has column offsets, so if you want columns with equal width without specifying size use this.

    <div class="row">
      <div class="col">col</div>
      <div class="col">col</div>
      <div class="col">col</div>
      <div class="col">col</div>
    </div>
    

    Also check out this link https://getbootstrap.com/docs/4.0/layout/grid/#all-breakpoints

    0 讨论(0)
  • 2020-12-07 22:11

    you can use this code inside col-md-3 , col-md-9

    .col-side-right{
      flex: 0 0 20% !important;
      max-width: 20%;
    }
    
    .col-side-left{
      flex: 0 0 80%;
      max-width: 80%;
    }
    
    0 讨论(0)
  • 2020-12-07 22:19

    Bootstrap 4 uses flex-box and you can create your own column definitions

    This is close to a 1.5, tweak to your own needs.

    .col-1-5 {
        flex: 0 0 12.3%;
        max-width: 12.3%;
        position: relative;
        width: 100%;
        padding-right: 15px;
        padding-left: 15px;
    }
    
    0 讨论(0)
  • 2020-12-07 22:25

    Create new classes to overwrite the width. See jFiddle for working code.

    <div class="row">
      <div class="col-xs-1 col-xs-1-5">
        <div class="box">
          box 1
        </div>
      </div>
      <div class="col-xs-3 col-xs-3-5">
        <div class="box">
          box 2
        </div>
      </div>
      <div class="col-xs-3 col-xs-3-5">
        <div class="box">
          box 3
        </div>
      </div>
      <div class="col-xs-3 col-xs-3-5">
        <div class="box">
          box 4
        </div>
      </div>
    </div>
    
    .col-xs-1-5 {
      width: 12.49995%;
    }
    .col-xs-3-5 {
      width: 29.16655%;
    }
    .box {
      border: 1px solid #000;
      text-align: center;
    }
    
    0 讨论(0)
  • 2020-12-07 22:27

    According to Rex Bloom response I have write a bootstrap helper:

    //8,33333333% col-1
    
    .extra-col {
      position: relative;
      width: 100%;
      padding-right: 15px;
      padding-left: 15px;
    }
    
    .col-0-5 {
      @extend .extra-col;
      flex: 0 0 4.16666667%;
      max-width: 4.16666667%;
    }
    
    .col-1-5 {
      @extend .extra-col;
      flex: 0 0 12.5%;
      max-width: 12.5%;
    }
    
    .col-2-5 {
      @extend .extra-col;
      flex: 0 0 20.833333325%;
      max-width: 20.833333325%;
    }
    
    .col-3-5 {
      @extend .extra-col;
      flex: 0 0 29.166666655%;
      max-width: 29.166666655%;
    }
    
    .col-4-5 {
      @extend .extra-col;
      flex: 0 0 37.499999985%;
      max-width: 37.499999985%;
    }
    
    .col-5-5 {
      @extend .extra-col;
      flex: 0 0 45.833333315%;
      max-width: 45.833333315%;
    }
    
    .col-6-5 {
      @extend .extra-col;
      flex: 0 0 54.166666645%;
      max-width: 54.166666645%;
    }
    
    .col-7-5 {
      @extend .extra-col;
      flex: 0 0 62.499999975%;
      max-width: 62.499999975%;
    }
    
    .col-8-5 {
      @extend .extra-col;
      flex: 0 0 70.833333305%;
      max-width: 70.833333305%;
    }
    
    .col-9-5 {
      @extend .extra-col;
      flex: 0 0 79.166666635%;
      max-width: 79.166666635%;
    }
    
    .col-10-5 {
      @extend .extra-col;
      flex: 0 0 87.499999965%;
      max-width: 87.499999965%;
    }
    
    .col-11-5 {
      @extend .extra-col;
      flex: 0 0 95.8333333%;
      max-width: 95.8333333%;
    }
    
    
    0 讨论(0)
提交回复
热议问题