Why does my Bootstrap 4 grid column seem to be devouring the rest of the columns?

Currently, I am delving into the world of Bootstrap 4 grid. My focus right now is experimenting with creating responsive boxes that adjust based on window size changes.

In my design, these are how the boxes should respond:

  • Large: Box 1, Box 2, Box 3, Box 4
  • Medium: Line 1 = Box 1, Line 2 = Box 2, Box 3, Box 4
  • Small: Line 1 = Box 1, Line 2 = Box 2, Box 3, Line 3 = Box 4

I have successfully achieved the desired layout for Large, Medium, and Extra Small screen sizes. However, I encountered an issue with the Small screen size (col-sm-). The problem arises when Box #4 starts covering up Box #2 and Box #3. You can view the issue in the following images:

bootstrap grid at lg, md, sm, and xs

When I attempted to uncomment the background-color property, the overlap between Box 4 and the other two boxes became more glaring. Here's a snapshot illustrating the problem:

Box 4 totally covers Box 2 and Box 3

Despite trying to add margins to the div-content class (green border) and padding to [class*="col-"], Box #4 continues to encroach upon the adjacent boxes. Here's the relevant snippet of code:

.container {
    border: 3px solid black;
}

.container .row {
    border: 3px solid red;
}

.row [class*="col-"] {
    border: 3px solid blue;    
}

.column-content {
    border: 3px solid green;
    margin: 10px;
    /*background-color: #ffbe5d;*/
}
<div class="container">
    <div class="row">

        <div class="col-xl-6 col-lg-3 col-md-12 col-sm-12 col-xs-12">
            <div class="column-content">Box 1</div>
        </div>

        <div class="col-xl-6 col-lg-3 col-md-4 col-sm-6 col-xs-12">
            <div class="column-content">Box 2</div>
        </div>

        <div class="col-xl-6 col-lg-3 col-md-4 col-sm-6 col-xs-12">
            <div class="column-content">Box 3</div>
        </div>

        <div class="col-xl-6 col-lg-3 col-md-4 col-sm-12 col-xs-12">
            <div class="column-content">Box 4</div>
        </div>

    </div>
</div>

If anyone could shed some light on why this issue occurs and offer suggestions to rectify it, I would greatly appreciate it. Thank you in advance!

Answer №1

Check out this awesome design!

.container {
  
    border: 3px solid black;
}

.container .row {
    border: 3px solid red;
}

.row [class*="col-"] {
    border: 3px solid blue;
    padding: 10px;
}

.column-content {
    border: 3px solid green;
    margin: 10px;
/*     background-color: #ffbe5d; */
}
<div class="container">
    <div class="row">

        <div class="col-xl-6 col-lg-3 col-md-12 col-sm-12 col-xs-12">
            <div class="column-content">Box 1</div>
        </div>

        <div class="col-xl-6 col-lg-3 col-md-4 col-sm-6 col-xs-12">
            <div class="column-content">Box 2</div>
        </div>

        <div class="col-xl-6 col-lg-3 col-md-4 col-sm-6 col-xs-12">
            <div class="column-content">Box 3</div>
        </div>

        <div class="col-xl-6 col-lg-3 col-md-4 col-sm-12 col-xs-12">
            <div class="column-content">Box 4</div>
        </div>

    </div>
</div>

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

Vertical text alignment alongside an image in multiple lines

I have been struggling with aligning multi-line text next to an image in a responsive design. No matter what I try, when the browser window is resized and the text becomes multi-lined, it always falls below the image positioned to the left of it. Can any ...

Manage the application of CSS media queries using JavaScript

Is there a method to control which CSS media query a browser follows using JavaScript? As an example, let's say we have the following CSS: p { color: red; } @media (max-width: 320px) { p { color: blue; } } @media (max-width: 480px) { p { col ...

Mobile application showing alerts for connected devices

In the process of creating a hybrid mobile app, I'm looking to incorporate notifications in the top right corner of the application. The frontend consists of html and angularjs, while the backend utilizes spring rest web service. To convert the front ...

Steps for developing a floating image transition using CSS and React

Looking to achieve a floating image transition using CSS and React, similar to the Divi theme header images. Check out the example below: enter image description here For more information, visit: ...

The IntroJs step is only partially visible on the screen

Currently, I am incorporating introJS into my application and encountering an issue where one of the steps is only partially visible on the screen. Despite trying various position settings such as auto, left, right, etc., this particular item consistentl ...

Issue with demonstrating the Material Angular expansion-panel feature

Exploring the world of Material Angular has been an exciting journey. Recently, I've been experimenting with adding components to my project. Currently, I'm focused on incorporating the expansion-panel component example into a dialog. However, de ...

`switch tabs visibility based on checkbox selection`

There are 4 tabs available on a JSP page: Tab 1, Tab2, Tab3, and Tab4. Initially, only Tab1 is enabled, allowing users to freely work within that tab. However, Tabs 2, 3, and 4 are disabled, preventing users from accessing their contents. A checkbox is lo ...

Continuous horizontal columns

Is there a way to create horizontal columns with inline-blocks, like the method described here, without having vertical gaps between items on the second line due to different heights? I want to eliminate the vertical gaps between the tiles using only CSS. ...

Looking for a drag-and-drop solution using Vanilla Javascript, no need for jQuery

Looking for assistance with creating a click-and-drag solution for a background image using Vanilla Javascript. I came across a jQuery solution on Codepen, but I need help translating it into Vanilla Javascript. Draggable.create(".box", { ...

Creating functional dropdown menus with popperjs in the latest Bootstrap version 5

Currently, I am attempting to implement dropdown menus in Bootstrap 5. According to my research, this feature requires Popper.js integration, but I am uncertain of the correct way to include it in my Laravel project that utilizes Laravel Mix. I have made ...

Odd spacing issue with Bootstrap's 'form-floating' label within a 'row' element

When using the form-floating class to achieve a floating label look, I encountered an issue with margins being disrupted when placing the class inside a row. For reference, here is how it looks without the row (label appears correctly): <link href ...

Attempting to assign a value to the Progress Circle

Can I modify the code to incorporate a hardcoded number instead of displaying "Goals completed:" and still have the progress bar reflect the percentage? I want to hide the prompt for users to input a number and handle all updates behind the scenes. Essent ...

Creating a notification for specific choices in a dropdown menu

I am working on a form that includes a select element with multiple options. Depending on the option selected, a different form will be displayed. My concern is if a user starts filling out one form and then decides to select another option, I want to add ...

What causes images to unexpectedly expand to fill the entire screen upon switching routes in Next.js?

I'm in the process of creating a website using Next and Typescript, with some interesting packages incorporated: Framer-motion for smooth page transitions Gsap for easy animations One issue I encountered was when setting images like this: <Link&g ...

What are the methods for choosing various boxes using the UP/DOWN/RIGHT/LEFT arrow keys?

This code snippet displays a 3x3 matrix where boxes can be hovered over and selected. The goal is to navigate around with keys and select boxes using ENTER. Can anyone provide guidance on how to achieve this functionality? <link rel="stylesheet" href ...

Limitations on Embedding Videos with YouTube Data API

I have been using the Youtube Data API to search for videos, but I am encountering an issue with restricted content appearing in the results. Specifically, music videos from Vevo are showing up even though I only want videos that can be embedded or placed ...

Transitioning from traditional desktop WPF Applications to HTML5-based solutions

Our small team within the department has been utilizing WPF for quite a few years now, consisting of just myself as the programmer and a designer. We primarily develop business applications for our company, such as shipment tracking tools and more. Lately ...

Fill a grid child with an excessive amount of content without specifying a fixed height

Check out this JS Fiddle example .grid { height:100%; display:grid; grid-template-rows:auto 1fr; background-color:yellow; } .lots-of-content-div { height:100%; background-color:orange; overflow-y:auto; } <div class="grid"> <p&g ...

What is the best way to style this specific HTML code using CSS?

Currently, I am facing an issue where two sets of text that are supposed to be inline with each other are not aligned properly. One of the texts is placed higher than the other even though they share the same CSS code. I want to be able to edit only one se ...

Using an image within the input group in Bootstrap 4

I'm a beginner in web development and I'm currently utilizing the glyphicon. This is how I'm currently using it: const className = `form-group ${touched && error ? 'has-danger' : ''}`; <div className={classN ...