Enhancing a bootstrap gallery with a zoom in effect

I need help creating a gallery using Bootstrap that resembles the style shown in this example:

While everything is functional, I am facing an issue with aligning the pictures properly after adding a hover effect. I tried placing each picture in individual containers, but now they are not lining up correctly due to variations in orientation (horizontal vs vertical). Does anyone have a solution to this problem? Here is the code for my project:

https://codepen.io/emmlll/pen/zYPLWxr

.img-gallery {
  overflow: hidden;
}

.img-gallery img {
  transition: all 1.3s ease;
}

.img-gallery:hover img {
  transform: scale(1.2);
}
<head>

  <title>Title</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="15777a7a61666167746555203b243b26">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

  <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b9dbd6d6cdcacdcbd8c9f98c9788978a">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
  <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8dece2fecdbfa3bea3bc">[email protected]</a>/dist/aos.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="event.js"></script>
  <style>
    @import url('https://fonts.googleapis.com/css2?family=Montserrat&display=swap');
  </style>
  <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Playfair+Display" />
  <link rel="stylesheet" href="style.css">
  <link href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="73121c0033415d405d42">[email protected]</a>/dist/aos.css" rel="stylesheet">

  <script>
    AOS.init();
  </script>
</head>

<div class="col-xl-12" id="gallery">
  <div class="row">

    <div class="col-lg-4 col-md-12 mb-4 mb-lg-0 ">
      <div class="img-gallery">
        <img src="https://media.istockphoto.com/photos/large-green-cactus-plant-in-a-yellow-ceramic-vase-picture-id118062993?s=612x612" class="w-100 shadow-1-strong rounded-3 " />

      </div>
    </div>

    <div class="col-lg-4 col-md-12 mb-4 mb-lg-0 ">
      <div class="img-gallery ">
        <img src="https://media.istockphoto.com/photos/cactus-plant-with-green-leaves-and-shovels-and-small-yellow-thorns-on-picture-id1012417960?s=612x612" class="w-100 shadow-1-strong rounded-3" />
      </div>
    </div>

    <div class="col-lg-4 col-md-12 mb-4 mb-lg-0 ">
      <div class="img-gallery mb-4">
        <img src="https://media.istockphoto.com/photos/large-green-cactus-plant-in-a-yellow-ceramic-vase-picture-id118062993?s=612x612" class="w-100 shadow-1-strong rounded-3" />
      </div>
    </div>

    <div class="col-lg-4 col-md-12 mb-4 mb-lg-0 ">
      <div class="img-gallery">
        <img src="https://media.istockphoto.com/photos/cactus-plant-with-green-leaves-and-shovels-and-small-yellow-thorns-on-picture-id1012417960?s=612x612" class="w-100 shadow-1-strong rounded-3" />
      </div>
    </div>

    <div class="col-lg-4 mb-4 mb-lg-0" style="display:flex">
      <div class="img-gallery">
        <img src="https://media.istockphoto.com/photos/large-green-cactus-plant-in-a-yellow-ceramic-vase-picture-id118062993?s=612x612" class="w-100 shadow-1-strong rounded-3 " />

      </div>
    </div>

    <div class="col-lg-4 col-md-12 mb-4 mb-lg-0 ">
      <div class="img-gallery">
        <img src="https://media.istockphoto.com/photos/cactus-plant-with-green-leaves-and-shovels-and-small-yellow-thorns-on-picture-id1012417960?s=612x612" class="w-100 shadow-1-strong rounded-3" />

      </div>
    </div>

  </div>
</div>

Answer №1

When creating a Bootstrap gallery, it's important to group all images for each column together. Each image shouldn't have its own column as this can cause spacing issues. Take a look at the example in the link provided and you'll see the proper structure. Simply place each image inside an img-gallery container to enable the hover effect.

Take a look below:

Note: If you prefer a masonry-style layout as shown in the example, add the mb-4 class to your images accordingly.

.img-gallery {
  overflow: hidden;
}

.img-gallery img {
  transition: all 1.3s ease;
}

.img-gallery:hover img {
  transform: scale(1.2);
}
<head>

  <title>Page Title</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f48e838388e2e3e8e3e3d2d7dcc3dcc1">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

  <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6020202f202a25343f35240511343f2b1e2a1e2b">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
  <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="175b5a434b5d5a5d54537a387d5a524b5b55224449785e5b664b55514a5b1542">[email protected]</a>/dist/aos.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="event.js"></script>
  <style>
    @import url('https://fonts.googleapis.com/css2?family=Montserrat&display=swap');
  </style>
  <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Playfair+Display" />
  <link rel="stylesheet" href="style.css">
  <link href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="057b78536f567b6c76697f6c727768793c79797664">[email protected]</a>/dist/aos.css" rel="stylesheet">

  <script>
    AOS.init();
  </script>
</head>

<div class="col-xl-12" id="gallery">
  <div class="row">

    <div class="col-lg-4 col-md-12 mb-4 mb-lg-0 ">
      <div class="img-gallery">
        <img src="https://media.istockphoto.com/photos/large-green-cactus-plant-in-a-yellow-ceramic-vase-picture-id118062993?s=612x612" class="w-100 shadow-1-strong rounded-3 " />
      </div>
      <div class="img-gallery">
        <img src="https://media.istockphoto.com/photos/cactus-plant-with-green-leaves-and-shovels-and-small-yellow-thorns-on-picture-id1012417960?s=612x612" class="w-100 shadow-1-strong rounded-3" />
      </div>
    </div>

    <div class="col-lg-4 col-md-12 mb-4 mb-lg-0 ">
      <div class="img-gallery ">
        <img src="https://media.istockphoto.com/photos/cactus-plant-with-green-leaves-and-shovels-and-small-yellow-thorns-on-picture-id1012417960?s=612x612" class="w-100 shadow-1-strong rounded-3" />
      </div>
      <div class="img-gallery">
        <img src="https://media.istockphoto.com/photos/large-green-cactus-plant-in-a-yellow-ceramic-vase-picture-id118062993?s=612x612" class="w-100 shadow-1-strong rounded-3" />
      </div>
    </div>

    <div class="col-lg-4 col-md-12 mb-4 mb-lg-0 ">
      <div class="img-gallery mb-4">
        <img src="https://media.istockphoto.com/photos/large-green-cactus-plant-in-a-yellow-ceramic-vase-picture-id118062993?s=612x612" class="w-100 shadow-1-strong rounded-3" />
      </div>
      <div class="img-gallery">
        <img src="https://media.istockphoto.com/photos/cactus-plant-with-green-leaves-and-shovels-and-small-yellow-thorns-on-picture-id1012417960?s=612x612" class="w-100 shadow-1-strong rounded-3" />
      </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

What makes the nav class different from the navbar class in Bootstrap?

Recently, I delved into learning about bootstrap and web development. To my surprise, I stumbled upon the nav and navbar classes in bootstrap 4. I'm curious to know what sets them apart from each other and when it's best to use one over the other ...

Is there a way to adjust the width of the info panel in an SVG to automatically match the width of the SVG itself?

I am looking to place the information panel at the bottom of my SVG map and have it adjust its width according to the width specified in the viewBox. This way, even if I resize the map, the info panel will automatically adjust to fill completely based on t ...

Combining an image and a link in HTML CSS: Tips for stacking elements on top of each other

I am currently working on adding a hyperlink to an image, so that when the image is clicked it will navigate to the specified link. However, I am having trouble with the formatting of the hyperlink as it is appearing smaller than the actual image. Below ...

Create an element that spans the entire width of the page

Having trouble adjusting the width of the .navbar? It seems to only grow to one side and setting it to 100% width doesn't expand it to fill the whole page. Can anyone provide some guidance or assistance? Here's the code: return ( <div cla ...

RAZOR - Strip image elements from variable with HTML content

In the code snippet below, I am using a helper to display content: @Html.Raw(Model.PageData.PageContent) My goal is to filter out any image tags that may be present. I have explored methods like .substring(), but they require specific indices or string n ...

Is there a flaw in how Firefox handles text-overflow and inline-block?

It seems that according to the text-overflow specification, the ellipsis effect only applies to inline elements: This property defines how content within an inline element is displayed when it overflows its container's boundaries in the inline dire ...

Stable element placement in relation to its container

While dragging an element, it obtains a position: fixed. This particular element is located within a modal that is directly nested inside the body element. In the image below, the modal appears in gray, while the rest of the body is black, and the button ...

Unable to exceed a width of 100% in Asp.net Tables

I searched for similar inquiries without success. Here is a snippet from my aspx file: <div align="center" style="height: 350px; overflow-y: scroll; overflow-x: scroll; width: 100%;"> <asp:Table ID="tblReport" Font-Size="11px" runat="server" ...

How can I incorporate classes from multiple CSS files into my WordPress theme?

Currently, I am utilizing wp_enqueue_style to incorporate two CSS files within a single function. However, the issue that arises is when I try to apply a class, it seems that only classes from one of the files can be utilized and it ends up overriding anot ...

What is the best way to place a list within a <div> element?

There is a <div> with an image in the background. I now want to include a list within that div, but I'm having trouble positioning it. Check out this image for reference In the image above, you can see the background and the list, but I'm ...

Styling multiple checkbox items in an Angular Material Autocomplete

Is there a way to adjust the height of autocomplete multiple checkbox items in Angular Material? I'd like it to look like this With a line item height of 18px But instead, it looks like this when using multiple checkboxes With a different checkbox ...

Is there a way to trigger both the link and the div element simultaneously?

Is there a way to make both the button and the link light up simultaneously when hovering over the div element, instead of just the button lighting up first? <div id="b1"; class = b> <a href="test.html">BUY</a> < ...

What is the precise width?

Here's a question for you: an HTML element has the following styles applied to it - width: 150px, padding: 3px, border: 4px, margin: 7px. What is the actual width of the element? I'm confused by this question because it specifies that the width ...

Create two div elements containing responsive images using HTML and CSS

Can someone assist me in creating responsive DIVs with images inside? Currently, the second div is appearing below the first one, and I'm struggling to make them scale based on mobile and tablet screen sizes. Here is the code snippet: .new_ba ...

I am interested in creating a similar layout using Bootstrap Studio

I've been attempting to align a text with borders and a button in one row, similar to the layout shown in this image, but I keep failing. I've experimented with different layouts such as two-column layout, one row, two-column layout, simple div, ...

Creating a responsive Google map within a div element: A step-by-step guide

I am experiencing difficulties with implementing a responsive Google map on my webpage. To achieve a mobile-first and responsive design, I am utilizing Google Map API v3 along with Bootstrap 3 CSS. My objective is to obtain user addresses either through th ...

Obtain the bootstrap CSS file

In all my various projects, I have been utilizing Bootstrap 3 and now I am interested in incorporating Bootstrap 4 cards into my work. However, I am struggling to locate the cards in a css format rather than the scss format. I personally don't think ...

What are the specifications for the opacity, width, and height of the background image in Bootstrap's

My current project has specific requirements that I need assistance with: I need the background image of the jumbotron to fit the width of the page and have its height scaled proportionally. The opacity of the jumbotron's background image should be ...

Having trouble with looping the CSS background using JavaScript in CodePen

Can someone help me with looping through CSS background images? Why is the background not changing in this code example: http://codepen.io/anon/pen/dGKYaJ const bg = $('.background').css('background-image'); let currentBackground = 0; ...

Position the form / delete button in alignment with the rest of the buttons

I have a table with options at the end like View, Edit, and Delete. I need the Delete button to be inside a form so that I can POST the delete request. However, my button/form is not aligning on the same line as expected. I have tried using the form-inlin ...