Enlarging the image upon hover by applying transform: scale, causing it to expand outward while maintaining visual clarity

Is there a way to make an image zoom in on itself without increasing the size of the surrounding area? I have tried implementing this concept using the following example: http://jsfiddle.net/7vY7v/130/. However, it doesn't work as expected. What am I doing wrong?

I am utilizing Bootstrap and applying the img-responsive class to the images as well.

Here is a demo of my progress so far: http://codepen.io/anon/pen/XJzexN

Code:

HTML:

<html>
<head>
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
    <link href='http://fonts.googleapis.com/css?family=Lato:100,300,400,700,900' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Roboto:400,100,300,500,700,900' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800' rel='stylesheet' type='text/css'>
    <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
    <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="container">

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

                        <img src="https://unsplash.it/800" alt="" class="img-responsive">

                </div>
                <div class="col-md-6 img-wrapper">
                    <img src="https://unsplash.it/800" alt="" class="img-responsive">
                </div>
            </div>
            <div class="pushdown"></div>
            <div class="row">
                <div class="col-md-6 img-wrapper">
                    <img src="https://unsplash.it/800" alt="" class="img-responsive">
                </div>
                <div class="col-md-6 img-wrapper">
                    <img src="https://unsplash.it/800" alt="" class="img-responsive">
                </div>
            </div>
        </div>


        <div class="container-fluid">

            <div class="row">
                <div class="people">

                </div>
            </div>
        </div>

  </body>

</html>

CSS:

.img-wrapper {
    display: inline-block;
    overflow: hidden;
}

.img-wrapper img {
    -webkit-transition: all .5s ease;
    -moz-transition: all .5s ease;
    -ms-transition: all .5s ease;
    -o-transition: all .5s ease;
    transition: all .5s ease;
    vertical-align: middle;
}

.img-wrapper img:hover {
    transform: scale(1.5);
    -ms-transform: scale(1.5); 
    -moz-transform: scale(1.5); 
    -webkit-transform: scale(1.5); 
    -o-transform: scale(1.5); 
}

Answer №1

Revise your HTML organization to look like this:

Improved Example

<div class="col-md-6">
    <div class="img-wrapper">
        <img src="https://unsplash.it/800" alt="" class="img-responsive>
    </div>
</div>

The issue with the element expanding was due to padding on the parent .col-md-6 element (with a padding-left/padding-right of 15px).

By switching the direct parent element to .img-wrapper, you effectively shift this and conceal the overflow.

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

Avoiding duplicate borders in grid layout

I'm working on a crossword puzzle design using css grid The blank cells have no color, while the other cells have a black border. The issue I'm facing is that the borders are overlapping. I've referred to similar questions on Stack Overfl ...

identify when the React component has reached the bottom of the element by reading the

Is there a way to access the scroll handler's event without being able to access offsetTop, scrollTop, etc? class App extends React.Component { handleScroll = e => { console.log(e.target.scrollTop); }; componentDidMo ...

Loading JavaScript and CSS files in an EJS file using Node.js

Here is the structure of my folder: server.js app --routes.js views --ace-builds-master --\src-noconflict --ace.js --index.ejs The 'views' directory contains my ace editor components and my index.ejs file. I am trying to include ac ...

The functionality of ItemSliding appears to be disabled when used in combination with

Could you please help me figure out why the Me button is not visible? I implemented the ItemSliding component. Here is the link to the stackblitz project. The issue is within the home folder. I am trying to create a list like the one below: UI https:// ...

Is a persistent left border / divider only on the even-numbered items in the list?

I have a layout of list items arranged in 2 columns, separated by a bottom margin after every 'row' of 2 items. While it's simple to add a left border to every even list item... I am curious if it's achievable to extend the border so ...

Tips for determining the width of an image and utilizing that measurement as the height in order to create a balanced square image

I am currently facing an issue with my code that is used to retrieve the width of an image which is set in percentages. Although I am able to obtain the width in pixels, I am struggling with correctly inserting the variable into the CSS property value usin ...

Automatically adjusting the size of images within a container

Currently, I am working on developing a custom admin panel to assist users in easily organizing their website data using a variety of templates. However, my main challenge lies in handling images. One specific template contains a div that is 380px by 150px ...

HTML vertical ruler

In my code, I have successfully created a horizontal line separator using the following CSS: /* line separator */ .aSeparator { border-top: 1px solid #5f656d; height: 1px; margin: 16px 0; } You can view the result here. This line separator adjusts ...

Tips for storing Json Data to be viewed offline in a Webview when online access is not available

I am currently utilizing Json Data to populate my HTML tables, and I have stored these HTML pages in the assets folder for offline accessibility. Within the HTML file, there is a table that is populated with rows and columns using Json Data. My goal is to ...

What is the best way to achieve a never-ending vertically scrolling image using CSS?

I want to incorporate a vertically scrolling image similar to the one on Adam Whitcroft's amazing landing page. I have tried examining his source code, but I am unable to grasp how he achieved it. The concept is to have the "I'm a scientist" text ...

django problem with bootstrap modal

I'm having trouble with the Bootstrap 4 modal in my Django project. When I click the button, the fade effect covers the entire screen, but the modal doesn't appear. I'm currently using Django 1.9. Does anyone have any suggestions on what mi ...

Error: The carousel in Bootstrap is throwing a TypeError because f[0] is not

We are currently utilizing Bootstrap Carousel to load dynamic slides, with each slide corresponding to an item in an array. AngularJS is employed to create the array and iterate through it. However, during execution, we encountered a javascript error Type ...

What is the best way to display a div beneath the highlighted text within a textarea field?

I have encountered a situation where I want to display a div (like a popup) when text is selected in a text area. However, when using mouse-down for this action, the position of the div sometimes does not align directly below the selected text. Below is t ...

What causes a scroll bar to appear when using position:absolute with images?

How can I ensure that an image at the top of a page functions as a background with 100% width on large screens, maintains a minimum width of 1000px, and doesn't display a scroll bar on screens smaller than 1000px? Below is the code I have been workin ...

An image inside this stylishly framed photo with rounded corners

.a { clip-path: polygon(10% 0, 100% 0%, 100% 100%, 10% 100%,10% 60%, 0% 50%, 10% 40%); } .a { position: relative; width: 500px; height: 500px; background:url("https://cdn.pixabay.com/photo/2020/02/16/07/55/thailand-4852830_960_720.jpg"); border-radi ...

Is there a way to toggle the visibility of images on a webpage without needing a specific trigger or buttons

I've scoured the depths of Google until my eyes hurt. Despite trying numerous codes, I've had no luck at all. I am convinced that there must be a way to make images appear and disappear in a random sequence while always having one image displayed ...

Paste the input text into the div element

I am attempting to create a simple form with one input field and one Div element. The goal is to have the text entered in the input field displayed in the Div when a button is clicked. Despite my efforts, I have been unable to get it to work correctly. I ...

What is the importance of including an explicit end tag for OBJECT elements?

There is an odd issue with the rendering of the word "Goodbye" in the following example, specifically in Chrome 14: <html> <body> <p>Hello</p> <object width="400" height="400" data="helloworld.swf"/> <p>Goodbye</p ...

Make sure to specify the max width of the Bootstrap container class to 940 pixels

Currently, I am utilizing Bootstrap 4 with the default container width on my desktop screen. For the main content section of my application, I would like it to be contained within a maximum width of 940px on larger screens. Should I override the existing ...

How to present images and descriptions in a list view on an HTML page using JSON data

I am new to using JavaScript and need help displaying images and descriptions in a list view on an HTML page retrieved from a JSON object. I have parsed a JSON object and extracted the image URL and description. Now, I need to showcase the Image and Descr ...