What is the best way to switch from rows to cards in Bootstrap version 5.3?

In my current project, Next JS is the framework I am working with. I am faced with the challenge of creating a card layout that adapts based on device size - for smaller devices, I want a plain card with the image on top and text below, similar to Bootstrap examples. However, for larger devices, I need the card layout to be in rows, with the image aligned on the left and the text on the right. Here is the code snippet I have been working with:

<div className="container pt-3">
          <div className="card">
            <div className="row row-cols-2">
              <div className="col-sm-6 my-auto d-flex">
                <Image
                  src="/main.webp"
                  className='card-img img-fluid rounded p-2'
                  width={400}
                  height={400}
                  alt="eco"
                />
              </div>
              <div className="col-sm-6 my-auto d-block">
                <div className="card-body-right my-auto d-block p-2">
                  <h1 className="card-title">Content</h1>
                  <h4 className="card-text">2000</h4>
                  <ul>
                    <li><h5>Content</h5></li>
                    <li><h5>Content</h5></li>
                    <li><h5>Content</h5></li>
                    <li><h5>Content</h5></li>
                    <li><h5>Content</h5></li>
                  </ul>
                  <p><a href="#" className='text-decoration-none'>Más características</a></p>
                  <a href="#" className="btn btn-primary px-5">Ver</a>
                </div>
              </div>
            </div>
          </div>
        </div>

Attempts were made to block certain classes, however none of them resulted in the desired outcome.

Answer №1

For optimal display, simply utilize the grid system as directed - employing full-width columns for smaller screens and half-width columns on larger screens.

In this instance, I have utilized the medium breakpoint for illustrative purposes. Also check out the complete page demo.

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

<div class="container pt-3">
  <div class="card">
    <div class="row row-cols-2">
      <div class="col-12 col-md-6 my-auto d-flex">
        <img src="https://via.placeholder.com/600x200" class='card-img img-fluid rounded p-2' width={400} height={400} alt="eco" />
      </div>

      <div class="col-12 col-md-6 my-auto d-block">
        <div class="card-body-right my-auto p-2">
          <h1 class="card-title">Content</h1>
          <h2 class="card-text">2000</h4>

          <ul>
            <li>
              <h5>Content</h5>
            </li>
            <li>
              <h5>Content</h5>
            </li>
            <li>
              <h5>Content</h5>
            </li>
            <li>
              <h5>Content</h5>
            </li>
            <li>
              <h5>Content</h5>
            </li>
          </ul>

          <p><a href="#" class='text-decoration-none'>More Features</a></p>

          <a href="#" class="btn btn-primary px-5">View</a>
        </div>
      </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

Creating a dynamic JSON object and retrieving the response in a JSP for data-driven documents

I am a beginner with the D3 API and I need to create a tree-like structure using a JSON file with hardcoded values. Additionally, I have a servlet that retrieves some values from a database which I want to dynamically convert into JSON in the servlet and s ...

Update Button Colour upon clicking the Button

I have multiple buttons lined up in a row on my webpage. I want the button's color to change when I click on them. Below is a snippet of my code: $( "button.change" ).click(function() { $(this).toggleClass( "selected" ); }); .Button { font-fa ...

I'm currently working on developing a chat system, but I'm facing an issue where I am unable to send multiple messages consecutively. It seems like there is a problem with the form

My chat application is not allowing me to post multiple messages. Here is the code snippet responsible for sending messages: window.typing = false; var posted = 0; var canPost = 1; var donotrefresh = 0; document.forms['send'].addEventListener(& ...

Displaying a notification for a multi-selection using JavaScript

I need help with a piece of Html code I have. It's a list of countries, and what I want is to show an alert when one or more countries are selected to display which ones were chosen. I'm working with JavaScript only and don't want to use Jqu ...

Modify the background color of one div based on the visibility of another div

My carousel consists of three divs representing a Twitter post, a Facebook post, and a LinkedIn post. These are contained within another div called #social-media-feeds. I am curious if it is feasible to adjust the background color of #social-media-feeds d ...

Doesn't the use of asynchronous programming in Node.js lead to a potential StackOverflow issue?

Recently, I identified an issue with the Node.js (single-threaded) platform: As requests are handled by the server and they undergo processing until being blocked due to I/O operations. Once a request is blocked for processing, the server switches ba ...

Navigate to the top of the page using Vue Router when moving to a new

Currently, in my Vue application, whenever I click on a <router-link>, it directs me to the new page but at the same scroll position as the previous one. This happens because the link only replaces the component. I am curious to know if there is a s ...

is there a way to modify the background color of a div element by comparing values in javascript?

Is there a way to dynamically update the background color of a div element within a table based on values stored in a json array from a database? ...

Simple steps to load various json files into separate json objects using node.js

I am new to working with Json and node.js My goal is to load a json file into a JsonObject using node.js, but I have been struggling to accomplish this task. I have created two files, one named server.js and the other jsonresponse.json. My objective is t ...

I'm interested in querying my mongodb collection data based on a particular field

I need help creating a list from my mongodb database that can be sorted by the "username" field. After learning about the limitations of namespaceing in mongodb, I'm trying to figure out how to sort my collection based on the "username" field. Here ...

Webpack has no issues building the files, however, the JavaScript fails to execute during runtime

I recently upgraded from Webpack v4 to v5, following the documentation and addressing any deprecation messages from the CLI. The build was successful, but when testing the application, I noticed that the JavaScript wasn't running and no errors were be ...

Create a configuration featuring filter options similar to Notion's functionality

The objective is to create a system that can establish certain constraints, similar to the way Notion handles filter properties. https://i.sstatic.net/plctW.png System A sets up the constraints and System C evaluates them, both using Typescript. However, ...

Preventing external requests from accessing a NextJS API route

Utilizing NextJS API routes to act as a proxy for a custom API developed with Python and Django that is currently not public, I followed the Vercel tutorial to implement cors as a middleware for the route. However, it did not provide the desired functional ...

jQuery causing trouble with AJAX in Rails

Currently, I am fetching a list of users from the controller side and generating the HTML code to append it. This is how I wrote the code: $.ajax({ type : "get", contentType : "application/json; charset=utf-8", url : "/users/sear ...

Tips for accessing JSON data stored as keys within a JavaScript object

I'm facing an issue with my Node.js lambda function that involves parsing JSON data received from an external application. The JSON data seems to be malformed and arrives as an object key, shown below: console.log(req.body) This results in: { &apo ...

Prevent the href from navigating to the next page when a doubleclick event listener is triggered

In my project, I am using an anchor tag that redirects to another page. However, if the user double clicks on it, I want to prevent the default behavior and stop the redirection. <a href="{location}">My Link</a> element.addEventListen ...

Retrieve database SQL information using JavaScript to display data

I'm struggling to push the value from a textbox to SQL and display it. Despite reading numerous topics, I still can't figure it out. My explanation skills are lacking, but hopefully you can understand what I'm trying to achieve, especially i ...

What is preventing "npx prisma db pull" from running when it reaches the introspection stage?

Hello, I am facing an issue while trying to add a table to my Supabase database. When I attempt to pull the table using npx prisma db pull command to update the Prisma schema, the process gets blocked. I also tried using npx prisma migrate dev but encount ...

What are the steps to incorporate a MenuItem within a div container instead of being a direct child of the Select component in Material-UI?

Embarking on my MUI journey, I am exploring how to utilize Select and MenuItem in tandem to create a checked dropdown functionality with the help of this reference link. My goal is to structure a header, body div for MenuItems, and a footer inside the sele ...

Ensuring the accuracy of query parameters in REST api calls using node.js

Each object type in the GET request to the API has a set of valid query parameters. var queryFields = { 'organisation': ['limit', 'page', 'id', 'search'], 'actor': ['limit', 'p ...