Clear Rows When Doing Multi-responsive Columns - Bootstrap

后端 未结 10 1133
不知归路
不知归路 2020-12-04 10:32

That title might not be very accurate but here is the situation:

\"The

相关标签:
10条回答
  • 2020-12-04 11:02

    I was looking for a solution as well and since my HTML gets rendered through a CMS I couldn't use the solution of the accepted answer.

    So my solution is:

    .teaser {
      // break into new line after last element
      > div:last-child {
        clear: right;
      }
    }
    
    .teaser {
      // two colums
      @media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) {
        > div:nth-child(2n+1) {
          clear: left;
        }
      }
    }
    
    .teaser {
      // three colums
      @media (min-width: @screen-md-min) {
        > div:nth-child(3n+1) {
          clear: left;
        }
      }
    }
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
    <div class="row teaser">
        <div class="col-sm-6 col-md-4">div1</div>
        <div class="col-sm-6 col-md-4">div2<br>more content</div>
        <div class="col-sm-6 col-md-4">div3</div>
        <div class="col-sm-6 col-md-4">div4</div>
        <div class="col-sm-6 col-md-4">div5<br>more content content<br>content</div>
        <div class="col-sm-6 col-md-4">div6</div>
        <div class="col-sm-6 col-md-4">div7<br>more content</div>
        <div class="col-sm-6 col-md-4">div8</div>
    </div>

    Hope this helps someone :-)

    0 讨论(0)
  • 2020-12-04 11:03

    Looks like the only solution to your problem is to set a min-height or a fixed height to your elements to that there are no inconsistensies that cause your issues.

    add this:

    .file-row-contain {
      min-height:250px;
    }
    

    ...set height according to your needs

    0 讨论(0)
  • 2020-12-04 11:05

    An .scss fix using bootstrap variables, taken from @jonas and @yog

    @mixin row-first-child($col-type) {
      .col-#{$col-type}- {
        &1:nth-child(12n+1),
        &2:nth-child(6n+1),
        &3:nth-child(4n+1),
        &4:nth-child(3n+1),
        &6:nth-child(odd){
          clear: left;
        }
      }
    } 
    
    .auto-clear {
      @media (min-width: $screen-lg-min){
        @include row-first-child(lg);
      }
      @media (min-width: $screen-md-min) and (max-width: $screen-md-max){
        @include row-first-child(md);
      }
      @media (min-width: $screen-sm-min) and (max-width: $screen-sm-max){
        @include row-first-child(sm);
      }
      @media (max-width: $screen-xs-max){
        @include row-first-child(xs);
      }
    }
    
    0 讨论(0)
  • 2020-12-04 11:12

    Bootstrap 4 introduces hidden-*-up and hidden-*-down classes. Very handy (and elegant) utility for situations such as these.

    Available classes

    • The .hidden-*-up classes hide the element when the viewport is at the given breakpoint or wider. For example, .hidden-md-up hides an element on medium, large, and extra-large viewports.
    • The .hidden-*-down classes hide the element when the viewport is at the given breakpoint or smaller. For example, .hidden-md-down hides an element on extra-small, small, and medium viewports.
    • There are no explicit “visible”/”show” responsive utility classes; you make an element visible by simply not hiding it at that breakpoint size.
    • You can combine one .hidden-*-up class with one .hidden-*-down class to show an element only on a given interval of screen sizes. For example, .hidden-sm-down.hidden-xl-up shows the element only on medium and large viewports. Using multiple .hidden-*-up classes or multiple .hidden-*-down classes is redundant and pointless.
    • These classes don’t attempt to accommodate less common cases where an element’s visibility can’t be expressed as a single contiguous range of viewport breakpoint sizes; you will instead need to use custom CSS in such cases.

    http://v4-alpha.getbootstrap.com/layout/responsive-utilities/

    0 讨论(0)
提交回复
热议问题