Utilizing CSS to create a zoom effect on hover for an image while preserving its original size was successful, however, the issue arises as only a corner of the image is visible

On my webpage, I have implemented an image that zooms in slightly when hovered over. Unfortunately, this animation has caused the image to only display one part regardless of whether hover is activated or not. I've attempted to troubleshoot by adjusting margins, padding, and positions but have had no luck so far. The code was added within a Bootstrap 4 environment, which may be playing a role in the issue.

If anyone can provide guidance on how to correct this problem without completely removing the hover effect, it would be greatly appreciated!

For reference, here is the Codepen link: https://codepen.io/amandathedev/pen/zyEyze

Below is the relevant section from the CSS:

.imgBox {
float: left;
position: relative;
width: 640px;
height: 360px;
margin: 0 auto;
/* justify-content: center;
display: inline-block; */
overflow: hidden;
}

.imgCard {
    position: absolute;
    top: 0;
    left: 0;
}

.imgCard img {
-webkit-transition: 0.4s ease;
transition: 0.4s ease;
}

.imgBox:hover .imgCard img {
  transform: scale(1.05);
  -webkit-transform: scale(1.05);
}

Answer №1

In order to ensure that your image scales from the center, you must set the transform-origin property to center in your CSS. Here is an example of how your CSS should be structured:

..additional CSS code here

.imgBox:hover .imgCard img {
    transform: scale(1.05);
    transform-origin: center;
    -webkit-transform: scale(1.05);
}

Answer №2

After reviewing your code snippet on CodePen, it appears that setting the width of the image to 100% may solve the issue at hand. You would modify your code like this:

.photo {
    width:100%
}

However, this adjustment causes the bottom of the image to be cut off. To address this, you will need to adjust the height of the imgBox that encloses the imgCard. Currently, it is set at 360px. Given how your code is structured, it might be easiest to choose a specific height that maintains the original aspect ratio of the image (upon experimentation, 478px seems to be the ideal height to display the entire image).

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 font size appears significantly smaller than expected when using wkhtmltoimage to render

I am trying to convert text into an image, with a static layout and size while adjusting the font size based on the amount of text. I prefer using wkhtmltoimage 0.12.5 as it offers various CSS styling options. Currently, I am working on a Mac. Below is a ...

Obtain span value using a CSS selector in Python

I need help extracting the value of a span using a CSS selector soup = BeautifulSoup("<body><main><div class='rentalprice'><span>3.000</span></div></main></body>") pagecontent = soup.find( ...

Is there a way to adjust the margin for a child DIV element using CSS?

Currently, I am working on my website located at www.buildinghunter.com. On the homepage, there are four div elements positioned in the bottom left corner of the page. I am attempting to align two specific divs (id=text-9 and id=text-10) with the other tw ...

CSS3 :target and display:none inconsistency problem in Internet Explorer and Firefox

Creating a one-page site with navigation tabs that toggle between hidden divs using :target CSS3 selector is my current project. To ensure the first div is visible upon page load, I implemented this line of code: document.location.href = "#div1"; The HTM ...

Include a proximity button onto the tabs

Currently, I'm diving into learning Bootstrap and one thing I'd like to implement is having an x next to each tab name for easy closing: <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__ ...

As the text in the textarea grows, the dimensions of the div containing it will

When text is entered in the div, its height increases accordingly. However, I would like the height to also adjust based on the size of the text when I press enter. Additionally, I need the width to remain constant until the text reaches the maximum width ...

Guide on embedding PHP code into a HTML div element using JQuery

I am having trouble loading PHP code into a div tag to display the results. The code I have listed below does not seem to work for me. If anyone can offer assistance in resolving this issue, I would greatly appreciate it. Here is the code snippet: <h ...

Browser resize affects the overlap of DIVs

I've seen similar posts before, but I believe the issue with my website (***) is unique. At full size, the website looks exactly how I want it to. However, when I resize the browser window, the text ("ABOUT INTERNATIONAL PARK OF COMMERCE.." and below ...

The identical animation is experiencing delays in various directions

Having an issue with my image slider - when clicking on the previous image button, the animation takes longer compared to when clicking on the next image button, even though the animation duration is set to be the same for both. Any idea why this might be ...

What is the process for linking my HTML page to my CSS stylesheet?

This is similar to what I have in the content of my HTML page. <link rel="stylesheet" type="text/css" href="/untitled2.css"> I thought this was right, but it doesn't seem to be functioning. Any ideas on what might be wrong? ...

Place the video element within the Canvas element

I'm trying to incorporate a video player on Canvas. My video has an alpha channel, and I want to play it over a jpg image. This is the code snippet I've put together: <video id="mainVideo" src="item0.mp4"> </video> <canvas id="m ...

Is there a way to left-align these items?

I currently have 10 divs arranged side by side. I am trying to align the last divs to the left instead of center, but the solutions I found so far are not working. I've checked Bootstrap's documentation and tried using <div class="d-flex ...

Achieving Full Height: Making one div occupy the entire height of another

Click here to see a jsfiddle example of what I'm working on. The jsfiddle above demonstrates the issue I'm facing. I am struggling to make the element with the ID #main_info fill the entire height of its parent element #main. My goal is to ensur ...

Tips for applying a linear gradient mask to div elements?

I'm attempting to create a fading effect on the edges of a div by using two overlay divs positioned absolutely on either side. My goal is to have the background of the page visible once the fade is complete, effectively masking the content of one div ...

Every time I attempt to create a detail page for a table, I am consistently greeted with an error message

Error: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /var/www/2909kher/entabell/detaljer.php on line 23 <!doctype ...

Django Ajax button fails to add item on initial click

My Django project features a dynamically rendered table for order items on the Cart page. Each item in the table displays the quantity, product name, total price, and more. To modify the quantity, I've implemented "add" and "subtract" buttons. Below i ...

Using PHP and jQuery to output content in HTML

I am facing an issue with displaying HTML content fetched from a database using the following code: $("#menuOverlay").append('<?php include('aggiungiPaginaComp.php');?>'); Although the code is functioning properly, when I view t ...

Learn how to dynamically update the dropdown text in bootstrap-vue.js

This is the dropdown code I am currently using: <b-dropdown size="sm" text="Update" split class="m-2"> <b-dropdown-item-button>Action</b-dropdown-item-button> <b-dropdown-item-button>Another ...

"Going beyond the ordinary: An exclusive look at the Outlook newsletter design

I'm struggling with adding text and a background image to a TD in a newsletter. While the background shows up, the text is not being displayed as expected. Below is the code snippet I've been using: {if !empty($aModules.mkNews)} ...

Issue with AJAX show/hide causing scrolling to top

I've implemented ajax show hide functionality to display tabs, but whenever I scroll down to the tab and click on it, the page scrolls back to the top. You can check out the example code in this fiddle: http://jsfiddle.net/8dDat/1/ I've attempt ...