Challenges with transitioning from Bootstrap 3 to Bootstrap 4 grid system

By utilizing Bootstrap 3.3.7, I managed to "row span" a div across multiple rows and utilize the remaining column space for other divs. Below is an example using this code:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <h1>Responsive Bootstrap 3.3.7</h1>
  <div class="row">
    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6" style="padding:0px">
      <div  style="background-color:green">level 1 - col-lg-6 col-md-6 col-sm-6 col-xs-6</div>
      <div  style="background-color:green">level 2 - col-lg-6 col-md-6 col-sm-6 col-xs-6</div>
      <div  style="background-color:green">level 3 - col-lg-6 col-md-6 col-sm-6 col-xs-6</div>
      <div  style="background-color:green">level 4 - col-lg-6 col-md-6 col-sm-6 col-xs-6</div>
      <div  style="background-color:green">level 5 - col-lg-6 col-md-6 col-sm-6 col-xs-6</div>
    </div>

    <!-- Additional divs here -->

  </div>  
</div>

I achieved the following layout with Bootstrap 3.3.7: Bootstrap 3.3.7 example layout

However, when I tried to replicate this behavior using Bootstrap 4.1.1, I encountered a different outcome:

Bootstrap 4.1.1 example layout

In Bootstrap 4.1.1, only the first two divs occupied the remaining 6 columns while the rest were pushed below the first div. I couldn't find a solution in the documentation. Can anyone help me achieve the original behavior in Bootstrap 4?

Answer №1

Using Bootstrap-4 with flex, it is important to establish relationships between columns and rows by creating containing elements. To group ten col-3 sections together, place them within a col-6 container and then add a new row to accommodate the smaller columns (now set as col-6 to utilize the 12-unit grid system).

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ceaca1a1babdbabcafbe8efae0f8e0fe">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container">
        <h1>Responsive Bootstrap 4.6.0</h1>
        <div class="row">
            <div class="col-6" style="padding:0px">
                <div style="background-color:green">level 1 - col-6</div>
                <div style="background-color:green">level 2 - col-6</div>
                <div style="background-color:green">level 3 - col-6</div>
                <div style="background-color:green">level 4 - col-6</div>
                <div style="background-color:green">level 5 - col-6</div>
            </div>
            <div class="col-6 p-0">
                <div class="row">
                    <div class="col-6" style="background-color:blue">Span 3 - col 3</div>
                    <div class="col-6" style="background-color:blue">Span 3 - col 3</div>
                    <div class="col-6" style="background-color:blue">Span 3 - col 3</div>
                    <div class="col-6" style="background-color:blue">Span 3 - col 3</div>
                    <div class="col-6" style="background-color:blue">Span 3 - col 3</div>
                    <div class="col-6" style="background-color:blue">Span 3 - col 3</div>
                    <div class="col-6" style="background-color:blue">Span 3 - col 3</div>
                    <div class="col-6" style="background-color:blue">Span 3 - col 3</div>
                    <div class="col-6" style="background-color:blue">Span 3 - col 3</div>
                    <div class="col-6" style="background-color:blue">Span 3 - col 3</div>
                </div>
            </div>
        </div>
    </div>

Furthermore, specifying col-6 in Bootstrap-4 automatically adjusts column layout across various device sizes without the need to redefine at each breakpoint. Only include col-lg-3 if different column configurations are desired for larger screens, following a progressive approach from small to large displays.

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

Encountering an issue following the update from Angular 8 to 12 - receiving the error message: "The 'controls' property is not present in the 'AbstractControl' type."

Previously, I had a fully operational code in Angular 8. Recently, I made the decision to upgrade from version 8 to Angular 12. The main feature of my project is a dynamic reactive form structured in a question-answer format. This form adapts based on the ...

Ensure HTML5 video fills window completely without any overflow

I'm currently developing a new open-source alternative to Plex and I am facing some challenges with the in-browser video player. My goal is to have the video player maximize its size within the window during playback, similar to what Chrome and Netfli ...

Increasing a numerical value in JavaScript

When inputting a prefix of 'A' and a value of 10, the desired result should be A1 to A10. However, in my current code, it is producing the output as 10A1 instead of just A1 to A10. Any assistance with this issue would be greatly appreciated. Apol ...

Creating a Single Button Photo Upload Functionality in ASP.net Using C# From a GridView Row

I am attempting to enable photo uploading from a row within a GridView, where the file name is generated based on the details of that row. While I have a functioning version of this feature, it does not seem to work consistently across different browsers. ...

What is the best way to highlight Navbar links when reaching a specific section?

When designing my website, I encountered an issue with the active navigation link style. It successfully changes when clicked and scrolled to the section, but does not update when the user scrolls away. How can I make the active style update on user scroll ...

Utilizing CSS and JavaScript for Image Masking

Is it possible to create a div that takes on the shape shown in this image and then fill it with an image? Alternatively, is there a way to transform an image into that particular shape using CSS or Javascript? Additionally, is it possible to arrange m ...

Populate List Items until Maximum Capacity is Reached and Increase the

Is there a way to make a ListItem fill the list vertically while also being able to overflow it if needed? I'm looking for a solution that would allow me to access the height of the empty space in the list, which I believe would be the minHeight. Som ...

Personalized Pagination for Data Tables

I have a client who needs a customized pagination view for DataTable. I want the pagination to look exactly like the image provided. https://i.sstatic.net/FFzkM.png To achieve this, I made modifications to the datables.js code. DataTable.js: $.extend(e ...

Hide the scrollbar in the div depending on the specified condition

I'm having trouble with this particular process and haven't been successful so far... I currently have a customized scrollbar within a div element, and what I am attempting to do is remove the scrollbar when the height of the div is less than 19 ...

When it comes to HTML and Javascript drawing, getting the positioning just right can be a challenge

I'm currently developing a control website for a drawing robot as part of a school project. However, I've been facing some challenges with the functionality of the drawing feature. Though I admit that the site lacks attention to detail, my main ...

Is it possible to choose only half of the elements using the :nth-child selector in

Consider this code snippet: <ul> <li>Hello Universe</li> <li>Hello Universe</li> <li>Hello Universe</li> <li>Hello Universe</li> </ul> Can we select exactly half of the total elements by ...

How can I transform an HTML element into a textarea using CSS or JavaScript?

While browsing a webpage, I discovered a <div> element with the class .plainMail and I want to find a way to easily select all its text by simply pressing Ctrl+A. Currently using Firefox 22, I am considering converting the div.plainMail into a texta ...

Incorporating new functionality into the current .js file to automatically collapse the navbar when clicking outside

Previously, I utilized .js for my sticky navbar in Bootstrap 4.1.3 and it worked perfectly. However, I attempted to add a function in the script to collapse the navbar on mobile devices when clicking outside the menu, but it wasn't successful. Here i ...

What is the best way to add an image to a question or answer in a JavaScript quiz?

I'm in the process of designing a quiz that revolves around using images as questions or answer choices. For example, presenting an image of a cat and asking the user to select the corresponding 'cat' button. Unfortunately, my attempts to i ...

What is the best way to generate a complete PDF of a webpage using pdfmake?

I'm currently developing a web application and facing the task of converting an HTML page, which contains multiple tables and datatables, to a PDF format. To achieve this, I've chosen to utilize the library pdfmake. Below is the script that I ha ...

Challenges with the Placement of Buttons

I am facing an issue with the code below: document.addEventListener("DOMContentLoaded", function(event) { // Select all the read more buttons and hidden contents const readMoreButtons = document.querySelectorAll(".read-more"); const hiddenConten ...

What is the correct method for handling images in HTML and CSS?

Hey there! Just playing around on jsfiddle and wanted to share this Destiny-inspired creation: http://jsfiddle.net/3mfnckuv/3/ If you're familiar with Destiny, you'll see the inspiration haha.. But here are a few questions for you: 1) Any ide ...

Having trouble determining the dimensions of a newly added element

I am using jQuery to dynamically add an image but I am unable to retrieve its dimensions (width and height). Below is the snippet of code from my HTML file: <input type="checkbox" id="RocketElement" data-id="1"> And here is the JavaScript/jQuery c ...

Activate the WebDAV feature within the .htaccess file

Can WebDAV be activated through an .htaccess file? I'm experiencing issues with Plesk not recognizing my modified config files that have WebDAV enabled. Is it feasible to enable WebDAV without using an .htaccess file? ...

Display a preview of a React component

Currently facing a challenge where I need to create a form for users to adjust the title, background color, button background, text color, and other settings of a component. I want to provide a live preview of the component as the user makes changes. I en ...