user2012677
user2012677

Reputation: 5745

Bootstrap 3, Media Query Clear:Left

I am using bootstrap and have a div with col-xs-12, col-sm-6, col-md-4.

Todo :

My code below seems to clear on every 1 items.

/* Extra Small Devices, Phones */ 
    @media only screen and (min-width : 480px) {
        .video-item:nth-child(1n+1){
            clear:left
        }
    }

    /* Small Devices, Tablets */
    @media only screen and (min-width : 768px) {
        .video-item:nth-child(2n+1){
            clear:left
        }
    }

   /* Medium Devices, Desktops */
    @media only screen and (min-width : 992px) {
        .video-item:nth-child(3n+1){
            clear:left
        }
    }
<div class="video-item col-sm-6 col-xs-12 col-md-4 img-sec">
   Box 
</div>

   

HTML STRUCTURE:

<div id="video-page" >
  <div class="container">
      <h2><center>Video Library</center></h2>
      <div class="span12 details">
        {% for article in blogs.videos.articles reversed %}
            {% include 'iframevideoid', video_url:{{article.content | strip| strip_html}} %}


                    <div class="video-item col-sm-6 col-xs-12 col-md-4 img-sec">
                        <div class="kind">
                            <a class="open-popup" data-target="#myModal" data-toggle="modal" data-video-id="{{videoid}}" >
<!--                                {{ article.image.src | img_url: 'large'| img_tag: 'Video', 'img-responsive' }}  -->
                               <img src="https://img.youtube.com/vi/{{videoid}}/mqdefault.jpg" alt="Video" class="img-responsive">
                            </a>
                            <p class="para">
                              <a data-target="#myModal"  data-toggle="modal" data-video-id="{{videoid}}">
                                 <h3 class="pare-head">{{ article.title }}</h3>                                     
                              </a> 
                            </p>
                        </div>
                    </div>
    {% endfor %}
      </div>


    <!-- Modal -->

    {%include 'modal-video' %}
  </div>
</div>

Upvotes: 0

Views: 61

Answers (1)

Jared Chu
Jared Chu

Reputation: 2852

Using min-width is incorrect in this case it will override all other media CSS. See my code below, I converted your CSS to blue (no clear) and red (clear: left) for easier to understand.

.video-item {
  height: 10px;
  width: 100%;
  background: blue;
  margin-bottom: 10px;
}

/* Extra Small Devices, Phones */ 
@media only screen and (max-width : 480px) { 
    .video-item {
        background: red;
    }
}

/* Small Devices, Tablets */
@media only screen and (max-width : 768px) {  
    .video-item:nth-child(2n){
        background: red;
    }
}

/* Medium Devices, Desktops */
@media only screen and (min-width:769px) and (max-width: 992px){
    .video-item:nth-child(3n){
        background: red;
    }
}
<div class="video-item">
</div>

<div class="video-item">
</div>

<div class="video-item">
</div>

<div class="video-item">
</div>

<div class="video-item">
</div>

<div class="video-item">
</div>

<div class="video-item">
</div>

<div class="video-item">
</div>

<div class="video-item">
</div>

As you can see, on medium devices, only 3rd items are red:

enter image description here

on small devices, only 2nd items are red:

enter image description here

And the extra small devices, all are red:

enter image description here

Upvotes: 2

Related Questions