Hover functionality is disabled when a div being hovered is nested inside another div

I am in the process of developing a webpage that showcases school events. I am attempting to create a div called "eventContainer" within which there is another div named "eventImgContainer" containing an image. When this image is hovered over, I want it to perform an action such as blurring or changing opacity.

However, I'm encountering an issue where the hover effect does not work when the div with the image is inside another element.

I have tried different syntax elements like ">" or "+" or ', ' related to hover effects but nothing seems to be working. Any insights into why this might be happening?

I am determined to achieve this using only CSS.

Here is the HTML:

<div class="eventContainer">
  <div class="eventDescription"><!-- code with event description here --></div> 

  <div class="eventImgContainer">
    <img src="1_Zdjecia/event_1/1.jpg" id="Photo1" title="football">
    <p class="hidedText">Go to Gallery</p>
  </div>
</div>

CSS:

.eventContainer {
    z-index: -1;
    position: relative;
    margin: auto;
    left: 0;
    right: 0;
    width: 700px;
    height: 270px;
    background-color: #E6E6E6;
    border: 4px solid white;
}

.eventImgContainer {
    position: relative;
    width: 375px;
    height: 217px;   
    top: 20px;
    left: 305px;
    margin: 0;
}

.eventImgContainer img {
    position: absolute;
    width: 100%;
    display: block;
}

.eventImgContainer:hover #Photo1 {
    opacity: 0.5;
    width: 400;
}

Answer №1

The latest CSS code you've written contains an error

.photoContainer:hover #Pic1 {
  opacity: 0.5;
  width: 400px;
}

Remember, CSS is case sensitive!

Avoid using negative z-index values (either remove the property or use a positive value).

Answer №2

Changing the z-index value from -1 to 1 made the code work for me. Also, your selector "eventimgcontainer" should be corrected to "eventImgContainer". However, the example still functions with the incorrect lowercase selector. The main issue was with the z-index property.

.eventContainer{
    z-index: 1;
    position:relative;
    margin:auto;
    left:0;
    right:0;
    width:700px;
    height:270px;
    background-color: #E6E6E6;
    border: 4px solid white;
}

.eventImgContainer{
    position:relative;
    width:375px;
    height:217px;   
    top:20px;
    left: 305px;
    margin:0;
}

.eventImgContainer img  {
    position:absolute;
    width:100%;
    display:block;
}

.eventImgContainer #Photo1  {
    opacity:0.5;
    width:400;
}

Answer №3

Start by deleting the z-index property

.pictureFrame{
  position:relative;
  margin:auto;
  left:0;
  right:0;
  width:700px;
  height:270px;
  background-color: #E6E6E6;
  border: 4px solid white;
}

Next, update the class name accordingly

.pictureFrame:hover #Image1{
  opacity:0.5;
  width:400;
}

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

Bootstrap grid shifting

Having an issue with configuring one of my bootstrap hero units to respond properly to an offset command: <div class="col-xs-6-offset-3 col-md-6-offset-3 col-lg-6-offset-3"> <div class="center hero-unit"> <h1>text</h1> ...

My website always fits on smaller resolution screens, but annoyingly, a horizontal scroll bar still appears

My website seems to have a horizontal scroll bar on smaller resolution screens, even though it fits. Any suggestions on making it fit better? If you're using a laptop, you'll notice that the scroll bar moves too far right to just show blank grey ...

Reasons why text does not show color when a style element is applied

I attempted to include a color and font family within an H1 tag using style, but unfortunately it did not work as expected. The color property had no effect on my current line of text. <h1 align="center" style="font-family: Arial, Helvetica, sans-serif ...

Is it possible to update the page title with JQuery or JavaScript?

Is it possible to modify the page title using a tag inside the body of the document with jQuery or JavaScript? ...

Are there any methods to adjust the spacing of bootstrap card grids and optimize the maximum limit?

Having a bit of an issue with my bootstrap cards in a Flask for loop. It's working fine, but every time I pass 3 cards, a new column starts and messes up the layout. Check out this screenshot for an example: https://ibb.co/jTvtSbq Also, the vertical ...

Eliminate the need for pressing the "tab" key on my website

I'm currently working on a horizontal web page layout and I'm looking for a way to disable the "tab" button functionality on my page. The issue arises because I have a contact form with textboxes located in the last div, and when users navigate u ...

What is the best way to eliminate the gap between the dropdown-toggle button and dropdown-menu items?

Why does a space appear between the dropdown-toggle button and dropdown-menu? Is there a way to remove this space? The box-shadow currently conceals the gap, but it becomes visible once the box-shadow is eliminated. Here is the code snippet: <!DOCT ...

Display a pop-up alert message when the session expires without the need to manually refresh the page

I have a query regarding the automatic display of an alert message. Even though I have set the time limit to 10 seconds, I still need to manually refresh the page for the alert message to appear. The alert message should notify the user that the session ...

the attempt to substitute an image with a canvas is unsuccessful

I attempted to utilize a function that transforms images into canvas elements. In my approach, I aimed to swap out the generated canvas with the corresponding image by using jQuery's .replaceWith() method, but unfortunately, the process did not yield ...

Tips for avoiding the display of the overall scrollbar while utilizing grid with an overflow:

In my react-redux application, I am utilizing the material ui Grid component for layout design. The structure of my code is as follows: <div> <Grid container direction="row" spacing={1}> <Grid item xs={3}> ...

The combination of sass-loader and Webpack fails to produce CSS output

Need help with setting up sass-loader to compile SCSS into CSS and include it in an HTML file using express.js, alongside react-hot-loader. Check out my configuration file below: var webpack = require('webpack'); var ExtractTextPlugin = require ...

Looking for browser prefixes for the `text-align` property? We've got you covered! Use `-webkit-right` for Google Chrome and Safari, `-moz-right` for Firefox, and `-o-right` for Opera. But what about

When it comes to browser prefixes or hacks, we often think of: (for Google and Safari) text-align: -webkit-right; (for Firefox) text-align: -moz-right; (for Opera) text-align: -o-right; But what about Internet Explorer? I'v ...

Stable element contained within a moving container

My content block has text that scrolls when it becomes too large. I'm trying to create an overlay div on top of this block, and I have implemented a solution in my example. I encountered issues where setting position: fixed for the overlay prevents i ...

Is it possible to modify the underline color while using the transition property in CSS?

One of the challenges on my website is customizing the navigation bar to resemble the BBC navigation bar. I want to change the border bottom/underline color using transition elements. Can anyone provide guidance on modifying the code to achieve this look? ...

How do I retrieve the title of the current page and store it as a variable within Flask using Python?

Consider the following scenario with an HTML page; <html> <head> <title>Desired Title Value Goes Here</title> </head> <body> <h1>Hello World</h1> </body> </html> ...

Guide to building an Angular circular progress indicator using Scalable Vector Graphics (SVG)

I have designed an angular circular progress bar, but I am facing an issue with making the percentage value dynamic. I have managed to retrieve the dynamic value from an API, but I am unsure of how to implement it in creating a circular progress bar using ...

Tips for creating a mobile-friendly website with Twitter Bootstrap

Having an issue with my site on mobile devices while using Twitter Bootstrap. The header is not displaying correctly when I resize the window, it appears like this: It should look consistent across all devices as shown below: Below is my HTML code: ...

The input field within the mat-form has been styled to match the background of the page using CSS

I am currently facing an issue with the code below: Html: <form fxLayout="column" fxLayoutAlign="center center" [formGroup]="deleteForm" (ngSubmit)="onSubmitForm()"> <mat-form-field color="accent" appearance="outline"> <input ...

Reposition the div element on mobile devices using media queries

Hello, I'm facing an issue on mobile with my website: dev site Today, I implemented a dropdown menu with flags to allow language switching. However, the dropdown in mobile is appearing under the hamburger nav bar. I was thinking of using media querie ...

what methods do you use to recall codes?

Hey there! I've recently started diving into the world of HTML, CSS, and Php. I'm curious, how exactly do experienced coders manage to remember so many functions? Is it something that comes with time and practice? As a beginner myself, this quest ...