Blend Bootstrap 4 columns with alternating rows of content

My website, using bootstrap, has a unique layout consisting of two columns side by side on desktop. In each column, the content is statically stacked with div elements of varying heights:

A | B
A | D 
C | D
E | F
E

Currently, I have set up this layout by utilizing two col-6 classes and populating them with corresponding content divs.

However, when it comes to mobile view, the design only allows for stacking the columns vertically like so:

A
A
C
E
E
B
D
D
F

The issue arises from the fact that in the above illustration, the A div is more closely related to the B div rather than the C div. My goal is to find a way to rearrange the layout for mobile devices so that it looks like this:

A
A
B
C
D
D
E
E
F

In essence, I need the contents of the two columns to merge together for the mobile layout, alternating between the div elements they contain. While my instinct suggests achieving this without JavaScript or custom CSS would be challenging within bootstrap's col-6 structure, I am open to exploring alternative solutions. Perhaps restructuring the overall layout without relying on col-6 or experimenting with card-deck could provide a solution.


The current code snippet:

<div class="container">        
    <div class="row pl-sm-3 px-1">        
        <div class="col-md-6 pt-sm-4">
          <div class="row pb-5 justify-content-center">
            <h1 class="display-4 text-light">   
                {{ $.Page.Title }}
            </h1>
          </div>
          <div class="text-center">
            {{ range .Params.pictures }}
                <img ... >
            {{end}}
          </div>
        </div>        
        <div class="col-md-6 pl-3 pr-4">
            <div class="mt-5 pt-5"></div>
            <div class="card">
            {{ range .Params.text}}
                <div class="card-body">            
                    ...
                </div>
            {{end}}
            </div>
        </div>
    </div>
  </div>

Answer №1

Utilizing Bootstrap for this task requires incorporating a small CSS code snippet. Through experimentation, I have devised a solution that integrates the card grid.

To implement Bootstrap cards, simply apply the card class to each child element (with the col class).

@media (min-width: 576px) {
  .card-columns.column-2 {
    -webkit-column-count: 2;
    -moz-column-count: 2;
    column-count: 2;
  }
}
<div class="container">
  <div class="card-columns column-2 row d-sm-block">
    <div class="col-12 order-1">A<br/>A</div>
    <div class="col-12 order-2">C</div>
    <div class="col-12 order-1">B</div>
    <div class="col-12 order-2">D<br/>D</div>
  </div>
  <div class="card-columns column-2 row d-sm-block">
    <div class="col-12 order-1">E<br/>E</div>
    <div class="col-12 order-2">F</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

Managing modules within the node_modules folder that have dependencies on .css files

Currently, I am involved in a project where we are utilizing a custom UI library that includes some dependencies. These components come with their own corresponding .css files. The structure of the source code looks like this: |- src |-| |- components ...

Issue with Bootstrap container's max-width not functioning

After implementing the code in the following manner: <link href="css/bootstrap.css" rel="stylesheet" type="text/css"> <link href="css/bootstrap-responsive.css" rel="stylesheet" type="text/css"> <style type="text/css"> .con ...

Tips for stopping an image from stretching the cell in flexbox using CSS

When using Flexbox to style elements, the width of the parent should be determined by the text inside child1. The image inside child2 should grow proportionately as the parent grows. However, it is important to ensure that the parent div does not exceed it ...

Managing Margins and Padding in Multiple Lines of Divs in CSS

Trying to understand the spacing issues that arise when tiling a series of divs within a parent div. Here is a link to the fiddle for reference: http://jsfiddle.net/SNSvU/4/. Below is the code snippet: <div id="prioritiesWrapper"> <div class="p ...

Presentation - hyperlink only functioning for final slide

I have a question about Lean Slider, which you can check out at My goal is to link each slide to a different URL. However, I'm facing an issue where only the code in the last slide seems to be executed and applied to all other slides. For example, if ...

"What is the best way to store the last three lines of text from a textarea into three separate variables

I am working with an HTML file that contains a textarea tag. My goal is to copy and paste text with multiple lines into the textarea and then use JavaScript to extract the last three lines into three separate variables. The textarea has the id "txt" a ...

The navigation bar fails to display correctly on Internet Explorer 10

Encountering problems with IE 10. View the code here. While on the latest Chrome and Firefox, all text appears in a single line, IE displays it differently. Other modern browsers produce a different result altogether. ...

Creating an Array of dynamically generated elements using jQuery

A dynamic table is being generated using jQuery's .append() function: $el.append('<tr data-id=' + data[i].id + ' data-token=' + data[i].token + '><td>' + data[i].order + '</td>\n\<td&g ...

A guide to accessing files and displaying their content by utilizing button clicks in PHP

Is it possible to navigate through the files in a folder by using buttons like Next and Previous, and then display the file contents within a table cell? Below is my attempted output, which unfortunately isn't functioning as expected: View Sample Ou ...

Restricting choices once user selects an option (HTML)

Currently, I am faced with a dilemma regarding two sets of options for an HTML form. One set consists of various units (such as cm, in, ft.), while the other set includes different locations. The selection of a unit would restrict certain location option ...

Form tags are closing automatically on their own

Currently experiencing an issue where a form tag is mysteriously closing on its own. In the process of troubleshooting and pinpointing the root cause of this unexpected behavior. Inside the table structure due to Netsuite usage, which complicates the debu ...

Activate a switch in a single table after its information has been transferred to a different table

I have a dilemma involving two tables - one displaying a list of items and the other serving as an empty favorites table. Users can select items from the first table and click 'Add' to move them to the favorites table. Once added, the 'Add& ...

Adjust the text within the treeview node for proper alignment

My treeview has nodes that display text, but when the length of the text increases, it moves to the next line and starts one place before the upper text, causing alignment issues. Is there a way to use CSS or JavaScript to properly align the text? Regards ...

Is there a way to set the default state of a checkbox in a spring-form?

I have set up my web content using spring-boot with .jsp files. The controller code is as follows: @Slf4j @Controller @AllArgsConstructor @SessionAttributes({"language", "amount", "words"}) public class LanguageController { private LanguageService lang ...

Modify the color of the menu in OpenCart 1.5.6.4 to give it a fresh

In the default theme of OpenCart 1.5.6.4, I am looking to change the background color of the dropdown menu which is currently defined by the background image 'menu.png' to a custom hex value. The CSS code for this section is shown below: #menu & ...

Creating an HTML Canvas using an AngularJS template

I am facing an issue with rendering html elements on a canvas using html2canvas JS. I am utilizing AngularJS for data binding on the html page, but unfortunately, the dynamic data is not showing up on the canvas generated from these html elements. For inst ...

Modifying an image with jQuery

Why won't this image change? Below is the relevant HTML, CSS, and jQuery code. HTML <nav id="desktop-nav"> <div class="logo"> <a href="#"></a> </div> <div> ... </div> ... CSS nav#desktop-nav . ...

Developing a JSP page by coding in html and css

Being a web designer, I find myself working on JSP pages to modify HTML and CSS for web application projects. However, I often feel confused by the JSP tags that I don't understand. Has anyone experienced this before? If so, how do you manage to edit ...

Utilize Jquery to locate and update the text of all div elements that have an empty id attribute

I need help with a task involving a list of divs, some with ids and some without. My goal is to identify all the divs within a specific class that have empty ids and change their inner text to say "no data available". Can this be done? My attempt using $( ...

Ways to evenly distribute children in a row using CSS

https://i.stack.imgur.com/HmziN.png The image above showcases the desired effect I am aiming for. It is important to note that the width of the container div may vary. The child elements should have consistent spacing between each other as well as the le ...