In a grid layout, the next image will smoothly transition when the user hovers over a div

I utilized grid layout to organize the elements on a page. However, when I attempted to add a hover effect to an image within a div, it caused some glitches so I decided against it.

Subsequently, I tried adding a hover effect to the entire div instead. Unfortunately, this resulted in the image of other divs getting transformed when hovering over one specific div. Can you please explain what is causing this issue and suggest a possible solution?

HTML

<div class="content1" id="webpages">
            <div class="cards" id="card1">
                <img src="https://dummyimage.com/300x168/000/ffffff&text=dummy+box1" alt="webpage unavailable">
            </div>
            <div class="cards" id="card2">
                <img src="https://dummyimage.com/300x168/000/ffffff&text=dummy+box2" alt="webpage unavailable">
            </div>
            <div class="cards" id="card3">
                <img src="https://dummyimage.com/300x168/000/ffffff&text=dummy+box3" alt="webpage unavailable">
            </div>
            <div class="cards" id="card4">
                <img src="https://dummyimage.com/300x168/000/ffffff&text=dummy+box4" alt="webpage unavailable">
            </div>
        </div>

CSS

/* Cards Layout Starts Here */

.cards {
    border: 1px solid #000;
    position: relative;
    height: 300px;
    width: 300px;
    overflow: hidden;
}

.cards img {
    position: absolute;
    top: 0;
    left: -50px;
    height: auto;
    width: 400px;
    transition: all 1s ease;
}

.cards:hover+.cards img {
    position: absolute;
    top: 22%;
    left: 0;
    height: auto;
    width: 298px;
}

.cards #plus {
    width: 50px;
    height: auto;
    display: block;
}

/* Cards Layout Ends Here */

/* Grid Layout Starts Here */

.content1 {
    display: grid;
    grid-template-columns: auto auto;
    gap: 20px;
}

/* Grid Layout Ends Here */

Answer №1

The correct css selector is .cards:hover img not .cards:hover+.cards img

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

Guide to filling a dropdown menu by aligning with the text it contains?

I've set up two dropdown select boxes below that are exactly the same: HTML <select id="ddl1" name="ddl1"> <option value="1">TEXT 1</option> <option value="2">TEXT 2</option> <option value="3">TEXT 3&l ...

Troubleshooting the lack of functionality with justify-items in CSS Grid

I'm facing an issue with my CSS Grid. I am attempting to set the justify-items property to start. Despite referencing the specification and watching a tutorial where it works, the property (and related ones) are not functioning as expected. In my tex ...

Adding extra space to the list items in CSS causes the text to become static and unaffected by fluctuations in the line-height

Here's the problem I'm facing: I have a basic list consisting of a shopping cart, login and user registration. I want to adjust the position of the list by adding padding, but every time I do so, the line height also increases. Is there a workaro ...

Displaying the Form div again without refreshing the page after a success message is shown through PHP AJAX

I am new to PHP and Ajax. My goal is to submit a form without refreshing the page, which I have successfully achieved. However, after submitting the form, a success message is displayed. What I want is for the success message to fade out and then show the ...

When attempting to use the jsonify method on a variable within an html file, the output is not displayed

Is it possible to store "jsonify" in a variable? I find the pure json format of "return jsonify(data)" unappealing, so I am looking for a way to enhance it using an HTML template with proper indentation. Here's the python code I have: from flask impo ...

Retrieve HTML elements from a string using PHP

Possible Matches: crawling a html page using php? Best methods to parse HTML I am trying to extract DOM elements from a string variable in my PHP script that contains an HTML page. How can I achieve this? For instance, if the string is something ...

Having trouble with Ajax Cross Domain functionality?

Similar Question: Ajax cross domain call Using the following code... var URLs = new Array(); var titulo = new Array(); $.ajax({ url: 'http://www.example.com.br', type: 'GET', success: functio ...

Choosing particular contenteditable divisions using jQuery

Consider the following HTML structure for a specific type of blog post editor: <div class="entry"> <div class="title" contenteditable="true"> <h2>Title goes here</h2> </div> <div class="content" contenteditable ...

Creating a PDF document using HTML code

I am interested in creating a PDF file from an HTML code that includes the stylesheet rules using PHP. Currently, I am attempting to achieve this with the MPDF library. However, the generated PDF does not resemble the original HTML page. Many elements app ...

Utilizing jQuery Methods within Node.js

Recently delved into the world of node.js and created multiple pages (such as login, signup, blog, etc). If I desire an effect in which: 1. Hovering over the "News" button triggers a slider to appear downwards, To make adjustments to an image within ...

Collapsing or expanding the Material UI accordion may lead to flickering on the page

import React from "react"; import { makeStyles } from "@material-ui/core/styles"; import Accordion from "@material-ui/core/Accordion"; import AccordionDetails from "@material-ui/core/AccordionDetails"; import Accordi ...

Construct a Product Showcase Page" (FreeCodeCamp) - Issue "Incurred upon clicking a .nav-link button in the navigation panel

Hi there! I've been working on a page programming task, but I'm having trouble with the "№5 “When I click a .nav-link button in the nav element, I am taken to the corresponding section of the landing page.” error. Can anyone help me figure ...

Tips for automatically breaking or paginating HTML in order to ensure that the resulting PDF mirrors the paginated HTML layout

I'm looking to implement a feature that automatically breaks or paginates HTML content in order to ensure that the resulting PDF matches the appearance of the original HTML. Requirement: If HTML content exceeds the size of an A4 paper, it should be s ...

Personalized radio button tags

Is there a way to ensure that all blocks are uniform in size with a 10px margin between them? Recently, the radio button was swapped out for a radio label, but now there is an issue with inconsistent sizes due to varying word lengths. How can this be res ...

CSS - Struggling to identify the source of unwanted horizontal scrolling?

Recently, I've been attempting to make adjustments to a responsive website that utilizes media queries. Despite my efforts, whenever the site is viewed on a mobile-sized screen, it consistently requires horizontal scrolling regardless of the screen&a ...

What is the method I can use to turn off an HTTP-EQUIV refresh with JavaScript

I am in the process of creating a status page that needs to refresh regularly. To achieve this, I have added a http-equiv refresh tag in the <head> section that automatically refreshes the page every minute: <meta http-equiv="Refresh" id="refres ...

Is it possible to automatically mute an HTML 5 video when closing the modal?

Is there a way to pause a video that plays in a modal and continues playing in the background when the modal is closed? I am using the Materialize library. <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script> <!-- Compiled ...

What are the steps to get an Icon to intersect with a v-app-component in a Vuetify project?

The locket is not overlapping with the v-app-bar. How do I make sure they intersect? <template> <v-app-bar :elevation="2" rounded> <v-row class="z-index"> <v-col cols="12" class="d-flex flex-column justify-center align ...

Handling Pop-up Windows in Python with Selenium

# Automation Setup from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.common.exceptions import NoSuchAttributeException, NoAlertPresentException from selenium.webdriver.support.ui import WebDriverWait from seleniu ...

The hover effect does not carry over to duplicated HTML

I successfully added a node, but I forgot to include the hover function of the node in my application. The hover function is not necessary, and I need it to work with ie8 compatibility. Here's my HTML: <div id="appendCell" style="color:green; colo ...