Transforming a horizontal row of images into a vertical stack on smaller screens using Bootstrap 4

I am facing an issue with a row of images on my website. On a normal large display, the images align nicely across the screen. However, when viewed on a smaller screen, the images shrink and remain horizontal instead of stacking vertically. How can I make this layout responsive so that the images stack vertically on smaller screens?

<div class="container">
  <div class="imgRow">
    <div class="d-flex justify-content-around">
      <div class="col-sm-3 w-25">
        <img
          src="image1.jpg"
          class="img-fluid"
          alt="..."
        />
      </div>
      <div class="col-sm-3 w-25">
        <img
          src="image2.jpg"
          class="img-fluid"
          alt="..."
        />
      </div>
      <div class="col-sm-3 w-25">
        <img
          src="image3.jpg"
          class="img-fluid"
          alt="..."
        />
      </div>
    </div>
  </div>
</div>

My current CSS for this row is:

.container .imgRow {
  padding-bottom: 10%;
}

@media only screen and (max-width: 768px) {

  .imgRow img {
    width: 100;
  }
}

I have attempted various solutions like removing the CSS properties, adjusting the image-fluid class, changing column sizes, eliminating the container, and modifying justify-content values without success.

Answer №1

To ensure your columns align in one line or separately, you can utilize Bootstrap's row feature and define the layout for each column accordingly.

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

<div class="container">
    <div class="row bg-dark d-flex justify-content-around">
        <div class="col-12 col-md-3 bg-warning">
            <img src="https://via.placeholder.com/200x100.png" class="mx-auto d-block img-fluid" alt="..." />
        </div>
        <div class="col-12 col-md-3 bg-primary">
            <img src="https://via.placeholder.com/200x100.png" class="mx-auto d-block img-fluid" alt="..." />
        </div>
        <div class="col-12 col-md-3 bg-info">
            <img src="https://via.placeholder.com/200x100.png" class="mx-auto d-block img-fluid" alt="..." />
        </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

The custom CSS file is not being recognized

I am facing an issue while trying to integrate two CSS files into my website. The second CSS file seems to be ignored, even though both files are properly loaded when inspecting with the Development Tool in Chrome. Here is a snippet from my Header: <l ...

What is the step-by-step process for executing the following functions: 1. magnify -> 2. spin 360 degrees -> 3. restore to original size before magnification -> 4. switch colors on and

Can you show me a demo featuring the following functions in order: 1. enlarge -> 2. rotate 360 degrees -> 3. resize to original size -> 4. change color (toggle) $(document).ready(function() { $('.tlist td div').click(function() { ...

Tips for positioning D3 circles along a half-circle arc

I'm trying to align a series of radios in a semi-circle formation, created from circles. The number of radios will vary and I need to ensure they stay centered. Here is my current setup: UPDATE: I just noticed that the order of the radios in the scre ...

What is the process of creating an additional coding workspace within Visual Studio Code?

I have been attempting to incorporate an about.html page into my website, but when I click the link nothing occurs. My goal is to connect it to a different workspace. Despite already completing the js and CSS aspects, the hyperlink for this about page re ...

Obtaining legitimate CSS property names for React dynamically

I am looking to create a dropdown menu in React that allows users to select camelized CSS properties (such as width, color, textAlign) for inline styles. Instead of manually inputting all the options for the dropdown, I had the idea of using the React.CSS ...

The HTML5 Canvas ellipse with a thick line width is displaying a quirky blank space

I am currently working on a drawing application using HTML5 canvas. Users have the ability to draw ellipses and choose both line and fill colors, including transparent options. Everything works smoothly when non-transparent colors are selected. However, ...

Received undefined response from Axios.get() request

While working with the code below, I encountered an issue. The axios get request from await axios.get('/products/api') is functioning properly and I can see the data in the console. However, for await axios.get('/users/api'), 'Unde ...

Can we incorporate various CSS libraries for individual components on our React site?

Let's say, I want to use different CSS libraries for each of my components - Home, About, Contact. Would it be feasible to utilize material ui for Home, semantic ui for About, and bootstrap for Contact? If so, what is the process for incorporating t ...

Tips for redirecting after an email has been successfully delivered

As a beginner in PHP, I've successfully set up an email system for a contact form on my website's front end. However, after sending the email, I want to hide the form and show a "thank you for the email" message. I've searched for solutions ...

Help with guiding and redirecting links

Here's the code snippet: <script> if(document.location.href.indexOf('https://thedomain.com/collections/all?sort_by=best-selling') > -1) { document.location.href = 'https://thedomain.com/pages/bestsellers'; } </script& ...

What is the best way to apply a box-shadow to a specific side of an element?

How can I apply a box shadow to only the right side of a block element? Currently, I achieve this by wrapping the inner element with a box-shadow in an outer element with padding-right and overflow:hidden to hide the other three sides of the shadow. Is the ...

"Troubleshooting issue with PHP code not running in a specific project within XAM

For some reason, the PHP codes are not parsing correctly and are just displaying as they are on the page. I am using xampp for this project, and all other projects on the same server are working fine. I have made sure not to use short tags like <?. I ...

Button to close on the right side of the navigation bar in Bootstrap version 4

Attempting to customize a navbar with Bootstrap 4, I have implemented the following modifications: Positioned the Collapse button on the right-hand side Separated the BrandName from the collapse area to ensure it remains on the left side Below is the co ...

What could be causing my Flask login function to not accept my post method?

Take a look at my code snippet: @app.route("/login", methods=["GET", "POST"]) def login(): session.clear() if request.method == "GET": return render_template("login.html") if request.method == "POST": rows = User.query.filter_b ...

Browse through web pages seamlessly without the need for page reloading or URL updates

After spending a significant amount of time searching for a solution to my idea, I stumbled upon a website that sparked my inspiration: Browsing through the website, I grasped the concept of what I want to achieve. I've been grappling with Ajax for s ...

Ensure that the width of the sibling div matches the width of its sibling image

I need help displaying an image with two buttons positioned below it. The dimensions of the image can vary, so I've set a max-width of 60% and max-height of 80%. However, I'm struggling to align the buttons correctly under the image - with the le ...

What is the best way to determine which DOM element is clicked when using the OnClick event? Can

Upon clicking an element: I seek to pinpoint the exact element. To prevent selecting multiple elements (e.g. with the same class) (and with or without an id), I am considering retrieving the absolute location/path in the DOM. Strategy: I have devised two ...

Guide to adding a tag in front of a text in HTML with Python

Searching for all the text within the html document and wishing to incorporate a span tag that contains additional information about each text as shown below def recursiveChildren(x): if "childGenerator" in dir(x): for child in x.childGenerator( ...

What is the best way to create a horizontal line above a div to serve as a home bar?

.topbar { background-color: white; position: fixed; margin: -10%; z-index: 10; height: 10%; width: 110%; } I have created this code for a div element, intending it to serve as a navigation bar on my website. My goal is to include an orange line at the top ...

PHP is experiencing issues when trying to insert data into the database

When I run a query in phpMyAdmin such as INSERT INTO table('نچجاعجان'); it appears correctly, but when I try to insert data through my PHP page, it displays in the field like this: ÙاننناÙنعن The col ...