Bootstrap 3's Clear:Left Media Query Feature

Bootstrap is being used, and there is a div with col-xs-12, col-sm-6, col-md-4 classes.

Task :

  • To add a clear on every 1 item for col-xs-12,
    add a clear on every 2 items for col-sm-6,
    and clear on every 3rd item for col-md-4.

The current code only seems to clear on every 1 item.

/* 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>

Answer №1

Utilizing the min-width property in this scenario is not advisable as it can override other media CSS styles. Take a look at the code snippet below where I have modified your CSS to use blue (no clear) and red (clear: left) for clarity.

.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>

On medium devices, only the 3rd items are displayed in red:

https://i.stack.imgur.com/ZrQ1n.png

On small devices, only the 2nd items are highlighted in red:

https://i.stack.imgur.com/qYTcw.png

And on extra small devices, all items are shown in red:

https://i.stack.imgur.com/N4RoV.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Safari browser is experiencing issues with the custom file upload script

My custom upload script allows users to easily select images for upload by clicking or dragging them into the designated box. A preview of the chosen image should appear, and this functionality works smoothly in Firefox and Chrome. However, I've encou ...

Tips for clearing out text in a <p> tag with javascript when it exceeds a specific length of 100 characters

Is there a way to automatically truncate text to (...) when it exceeds 100 characters inside a paragraph with the class .class? For instance, if I have a long paragraph like this: <div class='classname'> <p>Lorem ipsum dolor sit ame ...

What is the reason that certain CSS pages are not being utilized on my website?

I am facing issues with rendering my website on a tablet device, specifically with my last 2 css pages (800px.css and 800pxland.css). Despite working fine just hours ago, now they seem to be neglected while all the other ones work perfectly. I have tried ...

How can I create a custom AppBar transition using Material-UI?

Is there a way to incorporate transitions into the AppBar element within Material-UI? I have tried adjusting the class properties, but unfortunately, I'm not seeing any animation. Can anyone pinpoint what the issue might be? To see the code in action ...

Java Spring - The on-page styling is out of control

Currently, I am in the process of developing a taxi web application using Java Spring. After successfully creating the website with the help of a template, I encountered an issue when trying to integrate the login functionality. Strangely, the styling on ...

How to create a Vue.js animated navbar with scroll opacity

I am looking to create a fixed navbar that changes opacity based on user scrolling behavior. Initially, I want the navbar background to be transparent and then transition to white as the user scrolls down the page. An example of what I am trying to achieve ...

What is the process for setting up a bootstrap grid with a single column at the top and two columns

Can anyone help me figure out how to rearrange a bootstrap grid from three columns on desktop to one column above and two below on mobile? I've attempted multiple methods, but haven't had any luck... https://i.stack.imgur.com/oY2VU.png ...

What causes the content area of my <input> element to extend beyond the boundaries of its parent <span> element?

Please Note: I've been working on extracting code from a WordPress environment running the Salient theme. As of now, I haven't been able to simplify the issue to its core form. There is a possibility that I might figure it out myself, but I welco ...

How to Overlay a Semi-Transparent Object on a Background Video using CSS and HTML

Hey there, I'm encountering a puzzling issue with my website. I have a background video set up, and I wanted to overlay a floating textbox on top of it. However, no matter what I do, the background color and borders of the textbox seem to be hiding be ...

The functionality of aos.css seems to be malfunctioning on a Django-powered website

I recently set up a django backend website and attempted to incorporate CSS in my HTML using the following code snippet. {% load static %} <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-wid ...

Chrome: Box-shadow not visible on images with a background present

Recently, I have noticed an issue with the box-shadow not displaying on images with a background on my website. This problem started occurring in Chrome a few months ago, despite working perfectly fine around six months ago. To pinpoint the problem, I cre ...

Mastering the use of SVG icons in Angular 4+: A comprehensive guide

I have an icon.svg file with a collection of icons that I would like to use in my app, similar to how we display material icons. Does anyone have any ideas on how to include the file in the app and use these icons? I've tried looking for solutions a ...

Continuous Div Carousel with Looping in jQuery

I have developed a basic carousel to cycle through a series of divs, but I am facing some issues. I want the carousel to loop continuously so that after reaching "slide 07," it goes back to "slide 01." Unlike using a carousel plugin, I prefer having an ove ...

Guide on dragging and dropping without losing the item, allowing for continuous drag and drop functionality

function allowDrop(ev) { ev.preventDefault(); } function drag(ev) { ev.dataTransfer.setData("text", ev.target.id); } function drop(ev) { ev.preventDefault(); var data = ev.dataTransfer.getData("text"); ev.target.appendChild(document.getElementB ...

Issue with Font-Awesome icons failing to display properly when using the BootstrapCDN

Trying to integrate Font-Awesome icon fonts using the BootstrapCDN link with what seems like the latest version: <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"> The link has been added to the <hea ...

The Angulajrjs popup timepicker is not located within the input row

Currently, I am working on creating a popup timepicker within a modal. My main goal is to have the button inside the input field rather than after it. Does anyone know how I can achieve this? Thank you. If you need more context, you can check out my plun ...

When you scroll a fixed element on the page, the block is truncated

I made a modification for adding cart items and included a script for managing my cart The cart is supposed to stick to the right edge and scroll up and down on the page Everything seems to work, but there's a slight issue when I click on Add 1 and ...

What is causing the floated element to overlap the element below instead of vice versa?

div { background-color: #00FFFF; } p { width: 50px; height: 50px; border: 1px solid black; margin: 0px; } #p1 { background-color: red; float: left; } #p2 { background-color: green; } #p3 { background-color: orange; } #p4 { backgr ...

The issue of CSS3 Grid-gap not functioning properly on iPhone devices

I've been working on creating a CSS template and everything seems to be functioning correctly, except for the grid gap which doesn't seem to work properly on my iPhone. Here's the code I have so far: <div class="grid"> <h1 ...

Transitioning the implicit width

Using implicit width, which involves adding padding to an element containing text to give the parent container a specific but unstated width, can be quite elegant. However, it poses challenges when it comes to transitions. Is there a way to achieve a trans ...