What could be causing the CSS transition to fail?

Currently, I am facing an issue while trying to implement a hover effect for an image block. For some reason, the transition is not functioning as expected and I am at a loss as to why this might be occurring.

Here is the snippet of HTML code that I am working with:

<div class="area">
      <div class="mask"></div>
      <img src="http://placehold.it/300x300">
  </div>

Below is the CSS code that I have used (although the cursor works fine, the transitions seem to be non-responsive):

.area {
    width: 300px;
    display: block;
}

.area:hover .mask{
    display: block;
    cursor: pointer;
    transition: all 1s ease-in-out;
    -o-transition: all 1s ease-in-out;
    -ms-transition: all 1s ease-in-out;
    -moz-transition: all 1s ease-in-out;
    -webkit-transition: all 1s ease-in-out;
}

.mask{
    position: absolute;
    background-color: rgba(226,23,37,0.9);
    width: 300px;
    height: 300px;
    display: none;
}

Answer №1

Eliminate the display:none property from the .mask class and transfer the

background-color: rgba(226,23,37,0.9);
style to the .area:hover .mask selector:

.area {
    width: 300px;
    display: block;
}

.area:hover .mask{
    cursor: pointer;
background-color: rgba(226,23,37,0.9);
    transition: all 1s ease-in-out;
    -o-transition: all 1s ease-in-out;
    -ms-transition: all 1s ease-in-out;
    -moz-transition: all 1s ease-in-out;
    -webkit-transition: all 1s ease-in-out;
}

.mask{
    position: absolute;
    width: 300px;
    height: 300px;
}
<div class="area">
    <div class="mask"></div>
    <img src="http://placehold.it/300x300">
</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

What is preventing me from changing the text color of this span element to white?

For some reason, I'm trying to make the first two texts of each line appear in white, but my CSS doesn't seem to affect the span elements generated by JavaScript. Take a look at the code snippet below for more details. I'm still learning ho ...

Tips for preventing duplicate meta tags on your website

Currently working on my website utilizing next.js. A Question for Help The code snippet below can be found in the _document.js Head component. These meta tags are considered the root level. <meta name="description" content="~~~"/&g ...

Is it possible to insert both the name and value of a complete attribute within an element using a string in Razor?

There is a common way to achieve this in asp.net MVC Razor Engine: @{ string myValue = "foo" } <h1 hello='@myValue'></h1> However, I am interested in an alternative approach that might result in an error: @{ string myAttri ...

Images styled with CSS will be rendered smaller in size

My images are too large and automatically scaled down to fit the page width when printing. <img style="width:1300px" ... /> Is there a way to prevent this downscaling? I would prefer for them to be cropped at the border instead. ...

I am trying to display an element upon hovering using Jquery, but unfortunately, despite recognizing the event, it refuses to function as expected

I've been searching for a solution to show a submenu on hover by removing the hidden class that is hiding it. Despite trying various approaches, including using CSS and JavaScript, I haven't been able to make it work. Here is the code snippet I h ...

Building a row of five dynamic columns using Bootstrap's responsive design

I'm looking to set up a row with 5 responsive columns that have equal padding on all sides, but I'm struggling to find the best way to do this using Bootstrap. Here's my current HTML: <div class="row five-col-row"> < ...

Clicking the submit button on the form to enter a username and message in the chatbox doesn't appear to have any effect

My current issue involves a form I created for submitting a username and text message, but when I press submit, nothing happens. The strange part is that the code closely resembles my login and registration forms which work perfectly fine. Here is the code ...

Nav item with unconventional alignment in flexbox

My footer's central navigation item is not centered, and I'm struggling to align it while maintaining even spacing between the links. I attempted to center it by adding a margin-right: 45px in the CSS file at the bottom (commented out in the Code ...

`Move the Hover effect to a different element upon mouseover``

In my setup, I have the following arrangement: <div class="menuHomeCategorias Accesoriosclass"> <div class="categoryName Accesorios" name="Accesorios"> <p>Accesorios</p> </div> <img class="categoriasHome" alt="Ca ...

The Bootstrap Grid system quickly transitions between multiple columns simultaneously

My bootstrap responsive row initially resizes correctly as the window width decreases, but then it suddenly jumps to a layout where each item is on its own line. I would prefer a more graceful transition where items are added one at a time when they no lon ...

What is the best way to ensure that the width of dropdown menu items corresponds precisely to the width of the content

I have implemented the Reactstrap drop-down menu: import React from "react"; import { Dropdown, DropdownToggle, DropdownMenu, DropdownItem, } from "reactstrap"; export default class DropDownTest extends React.Component { cons ...

Can you explain the distinctions among <Div>, <StyledDiv>, and <Box sx={...}> within the MUI framework?

When exploring the MUI documentation, I came across a table of benchmark cases that can be found here. However, the differences between the various cases are not clear to me. Can someone please explain these variances with real examples for the following: ...

block height has become a constant challenge for me - despite my various attempts, I still cannot seem

Struggling with adjusting the height of my posts. Any help would be appreciated! For more details, please visit: <li> <div class="thumb-img"> <a title="Hiring a Professional Designer for Your Kitchen" href="http://www.mulberrydesignerkitc ...

Placing <IconButton> at the bottom right of <Paper> using React and Material UI without utilizing FAB

Issue: I'm working on implementing a react/material-ui design where I want to show an edit icon floating in the bottom right corner of a paper element. I've managed to get it to float in the bottom right of the entire screen, but that's not ...

Develop a responsive grid image system using BootStrap4 framework

What steps do I need to follow in order to develop a grid image system using bootstrap4 and css3? Take a look at this link to get an idea of what I am trying to achieve ...

fixed footer with fixed height on parent container

I have successfully implemented a sticky footer on my web pages by following specific instructions. http://css-tricks.com/snippets/css/sticky-footer/ The recommended approach includes using min-height:100% and not specifying the height property. .page-w ...

What is the best way to position an element at the bottom of a div?

In the div, there are elements like h1, p, and a. The goal is to have the h1 at the top, the a at the bottom, and the p in the middle regardless of its height. Check out the jsfiddle for a live demo. Here is the source code: HTML <div class="box"> ...

Ways to update the CSS classes of a bootstrap navigation menu

I am working with a bootstrap navigation bar that includes an option called "Add New Candidate" as a list item. I need to update its class from "nav-item has-treeview" to "nav-item has-treeview menu-open" when the user selects it, and also change the class ...

ASP TextChanged event is not triggering unless the user presses the Enter key or tabs out

My code is functioning correctly, however, the TextChanged event is triggered when I press enter or tab, causing my code to execute. I would like to be able to search for a record without having to press enter or tab. ASP: asp:TextBox ID="txtNameSearch ...

PHP variables should be included in a form submission when defined

When a user fills out the company information form, I use jQuery to validate the addresses. Within the submitHandler, there is a script that retrieves the longitude and latitude of the validated address. However, the long/lat data is not being submitted wi ...