Hover over div to center image

I created a unique Instagram display for my website and I am struggling to get the images to enlarge in the center of the parent div on hover.

Earlier, I managed to somewhat achieve this (although I have since changed the code), but now when I hover over the images, all sides of the image get cut off. It seems like the containing div is not wide enough to accommodate the full size of the images at the edges.

I've experimented with different approaches to fix this issue using CSS, as shown below. Apologies in advance if the code is redundant or confusing! Thank you!

// Parent div

.instagram_feed {
  overflow: hidden;
}

// Adjusts the grid size

#instagram-feed1 {
  display: flex;
  flex-wrap: wrap;
  height: auto;
  width: auto;
  margin: 4em;
}

// Controls image sizes in the grid

.instagram_feed .instagram_new {
  width:25%;
  float:left;
  padding:0 0px 5px 0;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

.instagram_feed img.insta-image {
  position: absolute;
  left:0;
  top:0;
  object-fit: cover;
  width:100%;
  height:100%;
  transition:all 0.3s ease0s;
  -webkit-transition:all 0.3s ease0s;
  -moz-transition:all 0.3s ease0s;
  -ms-transition:all 0.3s ease0s;
  -o-transition:all 0.3s ease0s;
}

.instagram_feed .insta-link {
  position:relative;
  display:block;
  background:#232323;
  padding-top:100%;
}

// Hover settings

.instagram_feed .insta-image:hover {
  opacity: 100;
  background-color: rgb(41,47,51);
  position:absolute;
  transform: scale(2,2);
  object-fit: cover;
  display: block;
  z-index:999;
  visibility: visible;
  transition-property: all;
  -webkit-transition-property: all;
  transition-duration: 0.3s;
  -webkit-transition-duration: 0.3s;
  transition-timing-function: ease;
  -webkit-transition-timing-function: ease; 
}

Answer №1

 .social_media_widget {
   overflow:hidden;

   //position relative !!
   position: relative;
 }

.social_media_widget .photo:hover {
  //center
  left: 50%;
  top:50%;
  transform: translate(-50%, -50%) scale(2,2);

  opacity: 100;
  background-color: rgb(41,47,51);
  position:absolute;
  object-fit: cover;
  display: block;
  z-index:999;
  visibility: visible;
  transition-property: all;
  -webkit-transition-property: all;
  transition-duration: 0.3s;
  -webkit-transition-duration: 0.3s;
  transition-timing-function: ease;
  -webkit-transition-timing-function: ease; 
}

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

Display video exclusively on desktop using Next.js: useEffect is unable to update a React state on a component that is unmounted

I am facing an issue with my Next.js website where I want to render a video only on desktop and not on mobile. To achieve this, I created a custom React hook to track the window size using the isDesktop state variable. While everything seems to be working ...

A guide to disabling daily checkboxes and retrieving the chosen values using Angular.js

Within a single table, I have incorporated a dynamic drop-down list that spans over 7 days. Additionally, I have implemented a "+" button that allows for the creation of additional rows dynamically for each day. Each row within the table features a checkb ...

Encountering an issue while invoking the helper function in Vuejs

Main view: <script> import { testMethod1 } from "../helper"; export default { methods: { init(){ console.log("Res:", testMethod1()); } } } </script> Helper: import DataService from "../services/data. ...

Ways to set a timeout for a hyperlink?

I have implemented two functions on the same element. One is AJAX for saving an image and the other is prettyPhoto ajax for displaying that image. Here is an example: This is the event > <a rel="prettyPhoto[ajax]" onClick="return false" > onMous ...

What is the best way to navigate through a JavaScript array?

After making an ajax call, I received the following output: "total":"3", "data":[{ "id":"4242", "title":"Yeah Lets Go!", "created":"1274700584", "created_formated":"2010-07-24 13:19:24", "path":"http:&bsol ...

Having trouble centering the CSS image gallery properly

I recently created a website using HTML and CSS, which you can view here. It seems to be functioning fine overall, but there are some spacing issues within the image gallery section. Specifically, the first space appears larger compared to the others. The ...

The synchronization between Typescript and the HTML view breaks down

I am currently working on an application that retrieves user event posts from MongoDB and displays them in HTML. In the Event-post.ts file, inside the ngOnInit() function, I have written code to retrieve the posts using the postsService.getPosts() method. ...

Navigating the carousel doesn't have to be complicated using Onsen-UI, especially when you want to

Currently, I am utilizing Onsen-ui along with angularjs. My issue lies in attempting to center images within a carousel, as they consistently align to the left. Below is the code snippet that I am working with: <ons-carousel direction="horizontal" styl ...

Setting a value for the identifier just one time

I've been grappling with an issue that's been on my mind for some time now. There are 14 divs on my webpage, and I need each one to be given a random ID (ranging from 1 to 14) every time the page loads. These divs all share the class ".image-box ...

Animating unvisited links with CSS

I have noticed that I am able to apply CSS color to unvisited links, but for some reason, I can't seem to do the same for CSS animations in Firefox and Chrome. Is this a limitation of the browsers or am I missing something? In the code snippet below, ...

Is there a way for me to figure out if a Primefaces RadioCheckbox has been selected?

Despite the numerous examples available on how to count checked checkboxes, I am facing difficulties in getting it to work. My goal is to enable a button when at least one checkbox is checked on the page, and disable it when none are selected. However, n ...

Is there an npm module available that can automate a daily task at a specified time in a Node.js environment?

Searching for an NPM Module to integrate into a Node.js application that can send notifications via email and SMS daily at 9am local time. Any suggestions or solutions would be greatly appreciated! ...

Ensure that you wait for the `grecaptcha` variable to load in Selenium using Python

As part of my automation efforts using Selenium, I encounter occasional failed form submissions on a website, often resulting in the error message below: 0.62d2e676.js:1 Uncaught ReferenceError: grecaptcha is not defined at Object.reply_chat_form_submi ...

Playing with background hues

Can anyone help me with this issue? I've been attempting to change the background color using jQuery upon document load, but it doesn't seem to be working. Any thoughts on what I might be doing wrong? http://jsfiddle.net/KczZd/2/ HTML: <d ...

How can one effectively generate room within an HTML/CSS file?

Within my div element, I have organized rows of three images each. These images are uniform in size. Previously, I used small, completely clear transparent images to create spaces between the images by explicitly setting their height and width. An example ...

Designing a unique customized top navigation bar in Magento 1.9.2

I recently attempted to create a unique top menu in magento 1.9.2 by modifying the Navigation.php file located at app/code/core/Mage/catalog/Block/. I added some custom classes in an effort to customize the menu. In order to achieve this customization, I ...

Switching back and forth between fluid text fields

Is there a way to navigate between dynamically generated textfields using an iterator from struts-tags? <s:iterator value="aList"> <td width="50px" align="center"> <s:textfield name="solField" size="2" maxlength="1" style="text-transform ...

The class (module) is not available for export

Module: import typeIs from './helpers/typeIs'; /** * @description Class of checking and throwing a custom exception. */ export default class Inspector { // Some code } In package.json specified the path to the file: { // .... "main" ...

Blend Image and Text with jQuery when Hovered Over

Alright, so here's the deal - I have an image that needs to smoothly transition to another image when hovered over. I also have some descriptive text that should crossfade into different text corresponding to the second image. The current setup is ki ...

Utilizing a different file to arrange and establish state

In a separate file called Origin.js, I have some data (objects) stored. This data is exported using the spread operator within an object named OriginState: Origin.js //info const info = { title: '', year: '', }; //images const ...