What's the best way to rearrange Bootstrap cards from a horizontal layout to a vertical layout for improved responsiveness?

I'm currently working with Bootstrap to align two cards horizontally, but I also want to ensure that mobile users can view the cards stacked in a column layout. I've experimented with adding 'flex-direction' in combination with the @media tag and adjusting the 'justify-content-center' property. Additionally, I have tried removing 'text-center', 'object-fit: contain;', and playing around with different display types. As someone new to front end development, any assistance would be greatly appreciated.

CSS:

.separado{
    display: inline-block;
    *display: inline; /* For IE7 */
    zoom: 1; /* Trigger hasLayout */
    width: 45%;
    text-align: center;
    margin-right: 5%; 
    margin-left: 5%;
    margin-bottom: 3%;
  }

  .imagen_top3{
    object-fit: contain;
    max-height: 600px;
    border: 5px solid #252727;
    padding: 1px;
  }

@media screen and (max-width: 980px) {
  .list-images img {
    width: 100%;
    margin: 3%;
    flex-direction: column;
  }
  .separado{
    zoom: 1; /* Trigger hasLayout */
    width: 100%;
    text-align: center;
    margin: 3%;
    flex-direction: column;
  }

  
}

HTML:

<div class="d-flex justify-content-center text-center">
      <div class="card text-center separado" style="width: 40%; background-color: #252727;">
        <img class="card-img-top imagen_top3" src="image1.jpeg" alt="Card image cap">
        <div class="card-body">
          <p class="card-text" style="color:whitesmoke">Hi im John</p>
        </div>
      </div>
      <div class="card text-center separado" style="width: 40%;background-color: #252727;">
        <img class="card-img-top imagen_top3" src="image2.jpeg" alt="Card image cap">
        <div class="card-body">
          <p class="card-text" style="color:whitesmoke">Hi im Peter</p>
        </div>
      </div>
</div>

Answer №1

To achieve the layout, utilize the bootstrap grid without the need for additional CSS:

<div class="row">
  <div class="col-xxl-6 col-md-12">
    <div class="card text-center">
      <img class="card-img-top" src="https://source.unsplash.com/ewqfhcrLoYA" alt="Card image cap">
      <div class="card-body">
        <p class="card-text" style="color:whitesmoke">Hi im John</p>
      </div>
    </div>
  </div>
  <div class="col-xxl-6 col-md-12">
    <div class="card text-center">
      <img class="card-img-top" src="https://source.unsplash.com/Edz4CIdzpA8" alt="Card image cap">
      <div class="card-body">
        <p class="card-text" style="color:whitesmoke">Hi im Peter</p>
      </div>
    </div>
  </div>
</div>

Except for styling purposes, remove any additional CSS provided.

Access the Codepen demo here: https://codepen.io/manaskhandelwal1/pen/rNMqYag

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

Send a string to directive via HTML

Trying to implement a "clipboard" directive following this example. In my case, I need to dynamically compute the string to be copied to the clipboard. The goal is to pass the output of a function that generates the string to the directive. Currently, I ...

Showing an image on a blurred background-image at the top of the webpage

Is it possible to overlay an image on top of another image, with the top image appearing blurred in the background? .background-image { background-image: url('https://images.pexels.com/photos/366968/pexels-photo-366968.jpeg?w=1153&h=750&a ...

Adjust Bootstrap form positioning to be fixed at the bottom of the page

Can anyone provide assistance with positioning this form at the bottom of the page? <form> <div class="form-group"> <input type="email" class="form-control" id="" aria-describedby="emailHelp" placeholder="Enter email"> &l ...

How can I set the input tag to reset back to 1 when a certain event occurs?

I am currently developing an HTML Snakes And Ladders game. On the settings screen, there is an input field where users can select the size of the board. Depending on their choice, they will be able to choose a maximum number of snakes and ladders. For exa ...

Adjust the top margin of a div to match the height of the screen within an iframe, ensuring cross-browser

Trying to adjust the margin-top of a div to 100% of screen height within an iframe seems to be causing issues with jQuery, as it either returns 0 or inaccurate values. While CSS3's 100vh can work as an alternative, it may not be supported in older an ...

Animate the transition between the icon and extended variant in Material-UI FAB

If you have a Material-UI FAB with the following code: <Fab size="medium" color="primary" aria-label="add"> <AddIcon /> </Fab> And you want to toggle to this other state: <Fab var ...

Is it possible for me to adjust these two images to fit the screen perfectly?

Technologies: CSS React JPG/PNG Objective: I am striving to resize two images to achieve this desired look: https://i.stack.imgur.com/B1b0h.png I am currently developing a 'skirt customizer' for either my mom or portfolio, where users can m ...

Creating a loader for a specific component in Angular based on the view

Creating a loader for each component view is crucial when loading data from an API. Here is the current structure of my components within my <app-main></app-main>: <app-banner></app-banner> <app-data></app-data> <app ...

Access an HTML page programmatically using JavaScript

Make sure to have a confirmation window pop up before submitting the form, and after confirming submission (by clicking OK), redirect to a confirmation page. Here's an example code snippet: <button type="submit" value="Save" id="Save" onclick="cl ...

Encountering issues with basic login functionality using Node.js and MongoDB - receiving a "Cannot

I'm experiencing some difficulties trying to set up a login for my website. I have a user registered in my database with the email: [email protected] and password 123. The issue arises when I attempt to use the POST method, as it returns the fo ...

If the image is not found, add a count instead of showing a new one each time

I have implemented a function to retrieve the two-letter country code: $ipaddress = $_SERVER['REMOTE_ADDR']; function ip_details($ip) { $json = file_get_contents("http://ipinfo.io/{$ip}"); $details = json_decode($json); return $detai ...

How come child elements are clipped in IE versions 9 and above when using the border-radius property with a fixed value?

When applying css border-radius:[some value] to a parent element and having a fixed positioned child element, I noticed that in Internet Explorer the child element appears to be 'clipped' into the parent. However, if I use border-radius:0 in the ...

I'm struggling to understand why the jQuery find() method isn't functioning as expected

UPDATE: In a twist of events not caused by syntax errors, but rather by a loading issue with the html template, it turns out that the checkbox update was happening prematurely. So if you're searching for an element that seems to be missing, it may sim ...

Simply modifying a custom attribute source using jQuery does not result in it being refreshed

Introduction: Utilizing jQuery.elevateZoom-3.0.8 to display zoomed-in images. The SRC attribute contains the path to the smaller/normal image The DATA-ZOOM-IMAGE attribute holds the path to the larger image used for zooming. Here is the HTML Code: ...

Troubleshooting Problems with Image Width in CSS Styles

I am facing an issue with displaying 3 images in a row side by side. The first image is bigger than the other two, causing them to be pushed down to the next row, which is not what I want. I have created a class and specified the height and width, but it d ...

Access a folder in JavaScript using Flask

I need to specify a directory in a script. $images_dir = '{{url_for('.../pictures')}}'; In my flask application directory structure, it looks like this: Root -wep.py -templates -gallery.html -static -pictures The images are stored ...

What is the best way to incorporate buttons that trigger PHP scripts within a MySQL database?

I have a MySQL database filled with various records that I've displayed in an HTML table on a webpage. I want to add two buttons next to each record, both of which trigger PHP scripts. For example, let's say the table lists the names of three pe ...

What is the best way to locate a web element in Selenium using Python when it does not have an ID

I'm having trouble selecting an element on the minehut.com webpage that doesn't have an ID. Despite trying CSS Selectors, I haven't had any success. The element I want to select is: <button _ngcontent-c17 color="Primary" mat-raised-bu ...

Ways to create a separator or divider between rows in a table

I'm currently working on creating a table layout and I want to include dividers similar to those seen on this website. Specifically, I am looking to have thin grey dividers between rows. I've attempted the following code, but it doesn't seem ...

Remove the unnecessary space at the bottom of the Mat Dialog

I'm currently utilizing Angular Material within my Angular application. One issue I am facing is the excessive whitespace at the bottom of a dialog that displays information about a post. How can I reduce or eliminate this unnecessary space? Take a l ...