Bootstrap gallery with images that resize proportionally

Attempting to create something simple, but currently unsure how to proceed. A few months ago, I had a concept in mind, but unfortunately lost the files and now feeling stuck.

Using Bootstrap to construct a gallery with two different image sizes: 1920x1200 for long images and 1200x1200px for short ones.

Attempting to organize it in a grid layout like:

<div class="row">
      <div class="col-md-6">
        <img src="yourImg" />
      </div>
      <div class="col-md-3">
        <img src="yourImg" />
      </div>
      ...
</div>

Desiring the final result to resemble the preview image here: https://i.sstatic.net/qFFpk.jpg

Additionally, each image should be centered within its respective column.

Experimented with using JavaScript to match heights, which worked well, but struggled with keeping the image inside the parent div due to JS not detecting div size. Background-image option was considered, but faced similar issues.

Seeking suggestions on how to successfully implement this design. Looking forward to re-building it effectively!

Appreciate any assistance provided! Thank you!

Answer №1

To ensure that the image fits perfectly within its container div, include the following CSS code:

img {
  max-width: 100%;
  max-height: 100%;
}

If you prefer to maintain the original aspect ratio of the image, you can use this alternative approach:

img {
  max-width: 100%;
  height: auto;
}

Answer №2

Initially, the html structure is incorrect, as each row should have 12 columns but all columns are in one single row.

The correct code structure should look like this:

<div class="row">
    <div class="col-md-6">
       <img>
    </div>
    <div class="col-md-3">
       <img>
    </div>
    <div class="col-md-3">
       <img>
    </div>
</div>

<div class="row">
      <div class="col-md-6">
         <img>
      </div>
    <div class="col-md-6">
         <img>
    </div>
</div>
 
<div class="row">
   <div class="col-md-3">
       <img>
   </div>
   <div class="col-md-3">
       <img>
   </div>
    <div class="col-md-3">
        <img>
    </div>
    <div class="col-md-3">
        <img>
    </div>
</div>  

This organization will help arrange the images as desired.

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

Reposition the element at the bottom of its parent element

I am facing an issue with the HTML structure in my application: <div class="work-item"> <div class="image-container"> </div> <div class="text-container"> </div> </div ...

Initiate Child Event within Parent Component

Before switching tabs in the parent component, I want the child tab to validate itself. My idea is to pass the onActive event from the parent to its children, <ClientInfo/> and <Details/>. This will allow the children to validate themselves a ...

Disable reloading when submitting and reset input fields after submission

I am working on developing a website where users can post things and comments without the need to refresh the page. I have encountered some issues while implementing this feature and need some assistance with it. My goal is to allow users to submit comment ...

How can CSS be used to select and style all elements within a <p> tag?

My fashion sense is specific: #style p { padding:10px; } I'm unsure which elements will be nested inside the paragraph. Is there a method to apply 10px padding to all elements within that paragraph? Can it be done like this? #style p everything ...

Attempting to include a navigation bar within the footer section of my layout page - the master page on my website

Is there a way to add a navigation bar in my footer on the layout page without having to add it to every individual page? I want the icon color for the active page to be red, but only apply this to the current page and not all pages. Currently, when I nav ...

Ways to verify the nodemon version that is currently installed on your local machine

On my Windows 10 machine, I recently installed nodemon locally in a project and now I'm curious to know which version is installed. Can someone please share the command to check the version of nodemon without needing to install it globally? My aim is ...

Implementing a password prompt in CodeIgniter using JavaScript

I need to delete a teacher as an admin, but before doing so, I want to require them to re-enter their password. However, I'm having trouble getting the delete function to work even though the prompt is displayed. Can someone help me figure out what I& ...

Issue: `TypeError: store middleware is not a valid function`

In my React-Redux code, I have successfully combined the store and reducer in previous apps, possibly due to different versions of React and React-Redux. However, when setting up a new React project with the latest versions, I encountered an error: T ...

What's the best way to display the spinner while making an axios request?

When I put the spinner on a component did mount method with a setTimeOut method inside, it shows. However, I want the spinner to display only when there is no content on the page. After the axios request finishes loading, the page content should be shown i ...

Tips on sending form data, including a file, to Ajax using the onclick() method

My Modal Includes a Form: <div class="modal fade bs-example-modal-lg" id="myMODALTWO" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" id="form-content"> <div class="modal-dialog modal-lg" role="document"> ...

Comparing Redux with passing state down to components as props from the top level of the application

With limited experience in react-redux, I am currently working on a smaller web-based application intended for around 100 users. At this time, I have opted not to use redux due to concerns about its complexity for such a small project. Instead, I have been ...

"Enhance Your Website with Various Hover Effects Using CSS across Multiple Elements

Has anyone experienced trouble with making the hover effect work in my onHover class and applying a display effect to span.box? Any ideas on how to fix this? .onHover { display: block; width: 200px; height: 20px; background: green; } .onHover:ho ...

Error message thrown by node express.js indicating that response headers cannot be reset once they have been sent

As a newcomer to both node and express, I may be making a silly mistake. If you want to see the complete source code, please visit: https://github.com/wa1gon/aclogGate/tree/master/server logRouter.get("/loggate/v1/listall", function(req, res) { let ...

What is the process for retrieving the text element from a React component when using React.cloneElement?

Can I centralize a translation function for all table header elements? const CustomersTable = () => { var headers=<> <th>Name</th> <th>Age</th> <th>Another text</th> </> ...

Using AJAX to send a request to a PHP file that populates a popover, but the functionality only works

I have created a basic search bar where with every .keyup() event, an asynchronous request is sent to a PHP file which then populates the data in a Bootstrap popover. The issue I am facing is that the popover displays the data only once. After entering th ...

Creating Diverse Pages with Unique Variables on Identical Layouts in Jekyll

I am currently using Jekyll to create static HTML pages, but I want to have the ability to generate similar layouts with different variables. Let me provide a simple example to illustrate my point: _config.yml title: Foo and Bar Generated index.html &l ...

Angular Unit Testing: Executing Multiple expectGET's within a Singular Test

I am facing an issue with a unit test that fails to read the JSON in the second request properly This is my implementation of the Config factory (function() { 'use strict'; angular.module('commercial.factories').factory(&apos ...

Prevent mouse over scrolling for every <select> element on a webpage using JQuery

My code seems to be having some issues. Can you help me figure out what's wrong? <script type="text/javascript" language="javascript"> //trying to disable scrolling on mouse over of <select> elements $(document).ready(function() { ...

The pseudo right arrow is failing to display in the vertical center

My pseudo right arrow is not displaying vertically centered within the .nav-link class. Can anyone suggest how I can achieve vertical alignment for my right arrow in an <a> tag? I have already attempted using top:50% but it did not work. Here is th ...

Rails 7 Importmap Pins does not work with Jquery source

Query Why does the importmaps command-generated source not function correctly with Bootstrap 4.6.1, while a tweaked source for the same version of jquery does? Challenge Details I developed a rails 7 application using importmaps for handling the javascri ...