A 2 by 2 grid displayed on larger screens and a 4 by 1 grid on smaller devices

I am curious about how to achieve a specific layout for different device sizes.

For medium and large devices, I want a 2 x 2 matrix layout with 2 rows and 2 columns.

On small and extra small devices or when resizing to a smaller size, I prefer a 4 x 1 matrix with 4 rows and one column.

To better illustrate my point, here is an ASCII representation:

1) 2 x 2 matrix (medium and large):

(b1)    (b2)
____________

r1c1    r1c2
r2c1    r2c2

2) 4 x 1 matrix (small and extra small):

(b1)
r1c1
r2c1
(b2)
r1c2
r2c2

The key aspect here is the merging of rows and columns in blocks when resizing to a small size. A block consists of two rows per one column, as indicated by (b1), (b2).

This concept should be scalable to accommodate multiple rows and columns.

I may be approaching this problem from the wrong angle.

In general, I aim to align text below images in a grid format, where each block's first row contains an image and the second row contains justified text.

How can I best address this challenge?

Answer №1

If I've grasped the gist of your query correctly, a simple solution would be to assign an order class for each column. Take a look at the code snippet below on various screen sizes like PC and mobile to observe how the layout and order differ.

UPDATE: Per your request, I have included margins for small screens.

/*FOR DEMO PURPOSES*/.col-md-6{border:1px red solid;padding:2rem}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">

<section class="container-fluid">
  <div class="row">
    <div class="col-md-6 order-1 order-md-1">Row 1 Col 1</div>
    <div class="col-md-6 order-3 order-md-2">Row 1 Col 2</div>
    <div class="col-md-6 order-2 order-md-3 mb-3 mb-md-0">Row 2 Col 1</div>
    <div class="col-md-6 order-4 order-md-4">Row 2 Col 2</div>
  </div>
</section>

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

Error: The value for $regex must be in the form of a string

Encountering a problem with an error in the Console: { [MongoError: $regex has to be a string] name: 'MongoError', message: '$regex has to be a string', waitedMS: 0, ok: 0, errmsg: '$regex has to be a string', code ...

What causes the small black line to appear on the right side of an image when it is turned into a link?

When I turn an image into a link, why does it always seem to display a tiny black line to the right of the image? ...

Angularjs bootstrap nav directive has some bugs that need fixing

My code works fine, but there's a problem: if someone clicks outside the target area (the text label), the directive doesn't fire. Here's my directive: //directive to change active menu class in bootstrap app.directive('activeClass&ap ...

The menu lacks responsiveness

I'm looking to create a responsive menu on my website where the button that opens the navigation will be hidden in "desktop mode". I came across some information on w3school, but I seem to have made an error. Can you assist me with this, please? Thank ...

Tips for dividing a div into percentages while maintaining a constant width for a div on the left side

I need help with creating a layout that involves 4 boxes. The first box (box1) should have a width of 50px on the left side, while the remaining 3 boxes should fill in the rest of the screen and be resizable. Can someone guide me on achieving this layout? ...

What is the best way to create a blurred effect on an image during loading, and then transition to a sharp image once it is fully loaded?

I'm currently working on a project where I want the images to display as a blurred preview initially, and then become clear once fully loaded. This is similar to the feature seen on Instagram, where the app shows a blurred image before displaying the ...

The execution of Ajax is not taking place

Hey, I'm facing an issue with AJAX in my project. It's working fine in other files, but for this specific instance where I call scripts/claim.php and pass an id parameter via GET, it's not functioning as expected. HTML <input type="hidd ...

What is the method for creating a loop that includes a radio-like button?

https://i.stack.imgur.com/YkheU.jpg How can I create a button that functions like a radio button? What is this type of button called? And how can I add radio buttons in a loop similar to the image above? I know the button input needs to be wrapped with ...

Struggling to achieve a horizontal scroll using 'overflowX' in MUI, but unfortunately, it's not functioning as expected

Is there a way to create a properly-sized card with a horizontal scrollbar in a paper format? I've tried using 'overflow' but it doesn't seem to be working in this scenario. import React from 'react'; import { makeStyles } fro ...

Using jQuery to define and apply style attributes

I'm currently working on a script that will add a left and right border to a button in a row of 3 buttons when that specific button is clicked. The goal is for the borders to remain while the button is active, and disappear once another button is clic ...

Drop and drag to complete the missing pieces

Here is a drag and drop fill in the blanks code I created. The challenge I'm facing is that I want users to be able to correct their mistakes by moving words to the right place after receiving points. <!DOCTYPE HTML> <html> <head&g ...

Locate the unordered list if its immediate parent is a list item

Here is the HTML code snippet I am working with: <div class="nav-collapse collapse"> <ul class="nav"> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret">< ...

How come all of my links keep opening in a separate window?

After upgrading a web project from Framework 2.0 to 4.0, I encountered an issue on the main page with links opening in new windows instead of within the same window. The problem seems to occur after visiting a page with a Crystal Report Viewer and returni ...

How can the background of a div be altered when text is typed into an input field?

I need help with the following code. I want to be able to change the background color of a div with the class "target_bg" from red (default) to green every time someone enters or types text into the input field. <div class="target_bg"></div> & ...

Interactive Form directly linked to SQLite3 database

Looking for assistance with converting a modal from static, fake data to dynamic data from an SQLite3 database. The goal is to display a table of existing data and allow users to add new rows by clicking a +New button. However, when trying to incorporate ...

Is there a way to eliminate the return?

Struggling to eliminate the unwanted return in my Wordpress loop. The layout is ruined by trying to display a thumbnail next to the entry: https://i.sstatic.net/j3Ozz.png Even using padding for the entry made it worse! Here's the code snippet that ...

Use jQuery to locate the nearest elements

Currently seeking a way to locate and choose the 5 nearest "li" elements (two, three, four, five, and six) with the class "active". Any suggestions? <li class="one">Hello</li> <li class="two">Hello</li> <li class="three">Hell ...

Utilize Bootstrap's JavaScript feature to prevent form submissions when there are invalid fields present and to address any issues where the form is not functioning properly

Utilizing Bootstrap version 4, I have a contact form within index.php that requires user validation. Upon submission, users should be alerted to any missed required fields. For instance, if a user submits without completing any fields, they should see the ...

Switching Styles in React applications

I am currently developing a React application and I have multiple stylesheets to restyle the same elements. For the purpose of this query, let's assume that I have two stylesheets with identical elements but different styles. Presently, in my app, I i ...

What are the steps to incorporate jQuery Mobile features into a simple webpage?

Recently, I utilized Adobe Dreamweaver CC 2014 to create a jQuery Mobile Webpage. While exploring its features, I discovered a unique capability within the jQuery Mobile Website. This particular webpage was connected to the necessary jQuery CDNs. What stoo ...