Show Div Overlay when mouse hovers using CSS3 transitions for a smooth effect

I have successfully implemented the overlay effect on hover, but now I would like to enhance it with a smooth transition using CSS3. Unfortunately, I haven't been able to find a working solution online yet.

Let's take a look at the code!

My setup consists of a div containing an image only. On hovering over the image, it reveals a colored overlay along with two text elements.

<div class="item">
     <img src="assets/images/blah.jpg" class="image">
         <a class="overlay" href="#">
            <h3 class="title">Some title</h3>
            <div class="description">
              <h4>Lorem ipsum dolor sit amet. consectetur adipisicing elit.</h4>
            </div>
         </a>
</div>

In my CSS, I included the following -transition code:

.item {
  position: relative;
  background-color: white;
  -webkit-transition: background-color 2s ease-in; 
  transition: background-color 2s ease-in; 
}

.overlay {
  background: white;
  position: absolute;
  display: none;
 }

.item:hover .overlay{
   display:block;
   background-color: black;
}

Despite this, the transition doesn't seem to work as expected! Can someone lend me a hand?

Should I consider changing the -transition property to incorporate display or all ?

You can view the version with working :hover effect in this jsfiddle link, albeit without the animation.

Your help is greatly appreciated

Link: https://jsfiddle.net/jonahmclachlan/nwhzLu1g/2/

Answer №1

To enhance the user experience, consider adjusting the display by modifying the opacity and incorporating transitions in the overlay rather than the item itself.

Visualize the effect through the following code snippet:

.item {
  position: relative;
  background-color: white;
}

.overlay {
  background: white;
  position: absolute;
  opacity: 0;
  -webkit-transition: background-color 2s ease-in, opacity 2s ease-in; 
  transition: background-color 2s ease-in, opacity 2s ease-in; 
 }

.item:hover .overlay{
   background-color: black;
   opacity: 1;
  -webkit-transition: background-color 2s ease-in, opacity 2s ease-in; 
  transition: background-color 2s ease-in, opacity 2s ease-in; 
}
<div class="item">
     <img src="assets/images/blah.jpg" class="image">
         <a class="overlay" href="#">
            <h3 class="title">Some title</h3>
            <div class="description">
              <h4>Lorem ipsum dolor sit amet. consectetur adipisicing elit.</h4>
            </div>
         </a>
</div>

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

Extracting text from a span tag with an inner span - a complete guide

Here is some HTML code: <span class="ui-cfs-sn-l" xpath="1"> ABC <span class="ui-cfs-txt">°⌃</span> </span> I have written python code to extract the text, resulting in ABC°⌃ element = dr ...

Ways to eliminate the yellow highlighting on a row

In my current application, I am incorporating jqGrid and aiming to apply custom styling to it. To start, my objective is to eliminate the yellow highlighting effect that appears when clicking on a row in the jqGrid css. Despite my attempts, I have been u ...

Adjust words to fit any screen size as needed

Looking for a small program that can dynamically change a word within an SVG? The goal is to create an effect where regardless of the word or group of words, they always stretch along the entire height (due to a 90-degree rotation) by adjusting the font si ...

Extracting text or value from a <span> element using its unique ID and storing it in a variable from a different website using cURL in

I am trying to retrieve the value or text within a span with a specific id from an external website using cURL. Once I have obtained this value, I need to store it in a variable. Here is an example of the span I am looking for: <span id="company" clas ...

Styling Profile Cards with EJS

I am currently working on refining the layout of this project. My objective is to have a "for each" card generated from server data entry, and have them displayed in rows, ensuring that there are three cards per row. However, my current code is not format ...

Update JavaScript variable value when there is a change in the onchange

Greetings, thank you for taking the time to read this. I am currently working with an input that includes a datepicker calendar. This calendar has variables called minDays and MaxDays which allow users to select a specific number of days. In my HTML form, ...

concealing elements using negative margins on tablet devices

I have an animated element on the ipad, moving from -200px to 1500px and being hidden due to overflow-x:hidden in the browser. However, when viewing this on the ipad, I am able to scroll "off screen" and reveal the hidden items, despite setting the body a ...

Is JSDOM able to handle media queries?

I understand that JSDOM may not have all the features of a full-fledged browser, but there is mixed information out there about its CSS support. While I've personally seen it parse CSS, responsive styles don't seem to function as expected. Can an ...

What is a simple way to center a box on a page without relying on margins?

I'm attempting to position a box in the center of the page without relying on margin. Here's what I've tried so far: .box-middle { vertical-align:middle; height:100px; width:100px; border:1px solid #ddd; } This approach h ...

Toggle class with jquery if the checkbox is checked

I am trying to achieve a simple task using jQuery. I have a checkbox inside a box, and I want to toggle a class on the box with a transition when the checkbox is checked. However, my code is not working as expected. Here is what I have: $(document).ready( ...

I am having trouble getting two similar Javascript codes to function simultaneously

Using a common JavaScript code, I am able to display a div when a certain value is selected. http://jsfiddle.net/FvMYz/ $(function() { $('#craft').change(function(){ $('.colors').hide(); $('#' + $(this ...

Customize the background color of FullCalendar in a React application

I'm currently using FullCalendar in my react app to showcase a calendar with events displayed. Right now, I have a day grid set up and I'm interested in changing the background color of the grid. The background color for today's date is alw ...

Styling Forms with SPAN Text in Place of Input or Select Controls

My current CSS is specifically designed to format labels above form input elements, but I am facing an issue when trying to replace the inputs with text from a database for displaying read-only data. Despite my efforts, changing the input fields to a span ...

Steps for incorporating the count() value in Django for web developmentTo embed the count() value while creating

I'm currently working on a web visual board project using Django. Here is the specific HTML section where I need to populate values from the database: <tbody> {% for obj in data_list %} <tr> <th>{{ ob ...

How can you alter the background color of a Material UI select component when it is selected?

I am attempting to modify the background color of a select element from material ui when it is selected. To help illustrate, I have provided an image that displays how it looks when not selected and selected: Select Currently, there is a large gray backgr ...

Upon submitting, retrieve the input values, evaluate the condition, and perform the necessary calculation

<html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.js"></script> </head> <body> <form> <p>query 1</p> <p> <input type="rad ...

Dynamically apply focus styles to div elements using CSS styling

In my dialog, I have a textbox on the left side and an icon (div) on the right side. When the dialog opens, both elements should be focused. Here is the HTML code: <input id="text-link" class="form-control" onfocus="this.select();" onclick="this.selec ...

Is the username you want available?

I am facing a challenge in my registration form validation process where I need to verify the username input using javascript and flask in python, but the implementation is unclear to me. The requirement is to utilize $.get in the javascript segment along ...

Encountered an issue while attempting to verify email through ajax with the database

After reviewing responses from multiple users here, I am aiming to verify if an email is already in the database. Below is the code snippet I am using: **HTML CODE** <div class="form-group"> <div class="col-sm-12"> ...

Is Height Responsiveness a feature?

I'm currently designing a custom responsive WordPress theme, but I've encountered a minor issue. On my page, I have multiple boxes arranged side by side. Each box is responsive in both height and width and contains an image with overlaid text. I ...