What causes the variation in width when I hover over this particular element?

#gallery {
  padding: 2rem 7%;
}

#gallery .row {
  display: flex;
  align-items: center;
  justify-content: center;
}

#gallery .row .col-md-3 {
  position: relative;
  overflow: hidden;
}

#gallery .row .col-md-3 img {
  height: 100%;
  width: 100%;
  object-fit: cover;
}

#gallery .row .content {
  position: absolute;
  background: greenyellow;
  padding: 3rem 2rem;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  transform: translateY(100%);
}

#gallery .row .col-md-3:hover img {
  transform: translateY(-100%);
}

#gallery .row .col-md-3:hover .content {
  transform: translateY(0);
}

.gallery-btn {
  border: 1px solid rgb(94, 21, 21);
  background-color: transparent;
  color: rgb(163, 27, 27);
  font-size: 18px;
  padding: 9px 26px;
}
<section class="gallery mb-4" id="gallery">
  <div class="row text-center mt-4">
    <h3>Our Gallery</h3>
  </div>
  <div class="row text-center mt-4">
    <div class="col-md-3">
      <img src="images/g-img-1.jpg" alt="" />
      <div class="content">
        <h5>Morning Coffee</h5>
        <p>
          Lorem ipsum dolor sit amet consectetur adipisicing elit. Perferendis, voluptatem?
        </p>
        <button type="button" class="btn gallery-btn rounded-0 mt-2">
                            Read More
                        </button>
      </div>
    </div>
    <div class="col-md-3">
      <img src="images/g-img-3.jpg" alt="" />
      <div class="content">
        <h5>Morning Coffee</h5>
        <p>
          Lorem ipsum dolor sit amet consectetur adipisicing elit. Perferendis, voluptatem?
        </p>
        <button type="button" class="btn gallery-btn rounded-0 mt-2">
                            Read More
                        </button>
      </div>
    </div>
    <div class="col-md-3">
      <img src="images/g-img-3.jpg" alt="" />
      <div class="content">
        <h5>Morning Coffee</h5>
        <p>
          Lorem ipsum dolor sit amet consectetur adipisicing elit. Perferendis, voluptatem?
        </p>
        <button type="button" class="btn gallery-btn rounded-0 mt-2">
                            Read More
                        </button>
      </div>
    </div>
  </div>
  <div class="row text-center mt-4">
    <div class="col-md-3">
      <img src="images/g-img-4.jpg" alt="" />
      <div class="content">
        <h5>Morning Coffee</h5>
        <p>
          Lorem ipsum dolor sit amet consectetur adipisicing elit. Perferendis, voluptatem?
        </p>
        <button type="button" class="btn gallery-btn rounded-0 mt-2">
                            Read More
                        </button>
      </div>
    </div>
    <div class="col-md-3">
      <img src="images/g-img-5.jpg" alt="" />
      <div class="content">
        <h5>Morning Coffee</h5>
        <p>
          Lorem ipsum dolor sit amet consectetur adipisicing elit. Perferendis, voluptatem?
        </p>
        <button type="button" class="btn gallery-btn rounded-0 mt-2">
                            Read More
                        </button>
      </div>
    </div>
    <div class="col-md-3">
      <img src="images/g-img-6.jpg" alt="" />
      <div class="content">
        <h5>Morning Coffee</h5>
        <p>
          Lorem ipsum dolor sit amet consectetur adipisicing elit. Perferendis, voluptatem?
        </p>
        <button type="button" class="btn gallery-btn rounded-0 mt-2">
                            Read More
                        </button>
      </div>
    </div>
  </div>
</section>

I've noticed a discrepancy in the image dimensions when I hover over them.

After inspecting, it seems there might be a width disparity causing this issue.

Could it be related to my use of Bootstrap 5?

Your assistance is greatly appreciated. Thank you!

Answer №1

Padding may be sourced from elsewhere, which is not advisable practice; however, you can resolve it by:

#gallery .row .col-md-3 {
    position: relative;
    margin: 5px 10px;
    padding:0;
    overflow: hidden;
}

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 is the Best Way to Line Up Divs of Varying Heights?

I'm struggling with aligning my divs properly. The issue I am facing is that my divs adjust their height based on the content within them, which is causing alignment problems. Below is a picture illustrating the current situation: https://i.sstatic. ...

Retrieving pictures by their unique identification number

Utilizing a flexslider, I have set up an image display feature as shown in the JSFiddle link below. The slider has been optimized to dynamically extract images from a specific directory, where images are named with numbers like 1023, 2045, 304654, and so o ...

What's the reason for the inability to resize fieldset using both?

Can someone explain why the resize control is not enabled on the fieldset element? The documentation mentions that resize does not work with: Inline elements Block elements that have overflow set to visible fieldset { resize: both; overflow: h ...

Custom Bootstrap 3 Panel Organization

I'm intrigued by the layout shown in the image attached. My attempts to recreate it using a combination of columns and rows have been unsuccessful. Could it be that I'm going about this the wrong way? ...

Issues with message display validation in jQuery

Validation has been applied to the form, and there are div elements within the input fields with corresponding IDs. The goal is to display error messages within those divs. Specifically, if an input field is missing, the errorMessage should be set in the ...

Using Django's view method in conjunction with the PermissionRequiredMixin

It’s interesting how we have a PermissionRequiredMixin with the permission_required attribute. I am curious to know how this can be achieved in a Django view method. Your input is greatly appreciated! Thanks! ...

Methods for dynamically populating dropdown lists with JavaScript and Bootstrap

I have collected all 387 regions for the current date and now I want to dynamically populate a bootstrap dropdown with these regions using JavaScript. Below is the basic HTML code for a bootstrap dropdown: <div class="dropdown"> <button class ...

How to apply background images to LI elements using CSS

I've been experimenting with CSS-generated tabs to display an active state of an arrow underneath the tab. I tried using the background position properties to position the image for the hover event, but it would extend beyond the predefined boundaries ...

Ensuring scroll position remains fixed post screen rotation in HTML/Javascript

Is there a foolproof method to retain the scroll position in an HTML document following a screen rotation? While this issue is specifically in a Cocoa Touch UIWebView, it seems to be prevalent across different platforms. The standard practice appears to re ...

Ways to stop Bootstrap collapse from displaying depending on a certain condition in bs5 framework

I've been struggling to figure out how to prevent a collapsible panel from opening or showing if a specific value is null. Despite multiple attempts, I haven't had any success. HTML <a href="#" data-bs-toggle="collapse" da ...

Displaying a message that prompts the user to overwrite the

Is there a way to create a confirmation popup in the ajax script for selecting information? I need a popup message to appear requesting permission to overwrite address component fields if they are empty. HTML: <html> [..] <div style="wid ...

Angular 2: Enhancing the table with Bootstrap Modal behind the scenes

I have a roster of students that I can manipulate using CRUD functions. Each student entry has an Edit button <table class="table table-bordered table-striped"> <thead class="studentHeader"> <tr> <td>Roll Number</t ...

Parenting and Child Components: Keeping the State in Sync

I am currently diving into my initial React project which focuses on a basic expense tracker for credit cards. While I'm still in the learning phase, I hope you can decipher the intent behind my code. My current roadblock involves mapping the state an ...

showing various perspectives upon clicking

I am in the process of creating a simple website using Rails to enhance my learning experience. One feature I am striving for is the ability to switch between tabs without changing the URL. For reference, you can check out an example here: http://tympanu ...

Seeking assistance to transfer div elements into a different div post an onclick event

I have a container that contains four separate divs. My goal is to append the remaining three divs to another specific div after clicking on one of them. Does anyone know how I can achieve this? <!DOCTYPE html> <html lang="en"> < ...

Determining the post_thumbnail's dimensions by force

How can I maintain a constant image size for post thumbnails on my website, regardless of the original image's dimensions? I attempted to achieve this using the following code: <?php if (has_post_thumbnail()) the_post_thumbnail(array(400, 200)); ...

Can you recall the name given to characteristics that do not have any value assigned to them (e.g. "checked" and "selected")?

There is a specific group of attributes in HTML that do not accept a value. For example, the checked attribute for the <input> tag and the selected attribute for the <option> tag fall into this category. Do you know what term is used to refer ...

Modifying the design of a webpage using JavaScript, proceeding to the next step, and then navigating back

I am currently working on enhancing the user experience by providing customers with the option to either log in to our booking system or fill out a form with their information. When they first arrive on the page, they are presented with these two choices. ...

The Html.BeginForm() function is directing to an incorrect action within my controller

I'm facing an issue with my HTML form that is built using Html.BeginForm(). Even though I specify the controller name and action name, it always redirects to the wrong action. Here is a snippet from my view: @using (Html. BeginForm("AdminPanelResult" ...

Expanding Node Automatically with Bootstrap 4 on Page Load

I am currently learning Bootstrap 4, JavaScript, and other technologies. One of the things I want to achieve is to automatically expand a node when the page loads for the first time. However, my attempts to modify the data-collapse attribute have been uns ...