A
A
Alexander-K2015-06-13 17:29:11
HTML
Alexander-K, 2015-06-13 17:29:11

How to fix a bug in bootstrap when an empty space is formed between columns equal to the width of the column?

With this code:

<div class="container">
  <div class="row">
    <div class="col-md-2 col-sm-4 col-xs-6">1</div>
    <div class="col-md-2 col-sm-4 col-xs-6">2</div>
    <div class="col-md-2 col-sm-4 col-xs-6">3</div>
    <div class="col-md-2 col-sm-4 col-xs-6">4</div>
    <div class="col-md-2 col-sm-4 col-xs-6">5</div>
    <div class="col-md-2 col-sm-4 col-xs-6">6</div>
  </div>
</div>

On mobile it should be like this:
8a8da629754643cea42de42a608b2495.pngBut in reality it often turns out like this:
6541e24deb654b45b31dbad897059042.pngHow to remove this bug?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Zuev, 2015-06-13
@Alexander-K

Well, this is the usual behavior of float:left for different element heights. For mobile, the following code may help

@media (max-width: 767px) {
  .col-xs-6:nth-child(2n+1) {
      clear: left;
  }
}

W
WhiteSama, 2015-06-13
@WhiteSama

columns of the same width must be, or indicate different co-md

A
Andrey, 2015-06-13
@f-end

If you use strictly the bootstrap tools specifically designed for this, then use an additional block with the .clearfix class ( getbootstrap.com/css/#helper-classes-clearfix )
which is displayed only on certain resolutions - those where the problem is observed. See Responsive utilities ( getbootstrap.com/css/#responsive-utilities )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question