CSS Transitions don't work on display:block/none; You can manage to give that effect using visibility/opacity properties.
Check this example, You can manually add the transition-delay property if you really want it to add.
.main_div {
width: 100px;
height: 100px;
border: thin black solid;
position: relative;
}
.main_div .overlay_div {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
visibility: hidden;
opacity: 0;
transition: all 1s ease-out;
}
.main_div:hover .overlay_div {
visibility: visible;
opacity: 1;
transition: all 1s ease-in;
}
<div class="main_div">
<div class="overlay_div">
some text
</div>
</div>
Answer from Deepak Yadav on Stack Overflowhtml - CSS3 : Fade in on hover and Fade out when hover is gone - Stack Overflow
css - Fade Effect on Link Hover? - Stack Overflow
css - Fade in fade out on image hover using CSS3? - Stack Overflow
How to fade in text on hover?
How do you fade an image on hover with CSS?
How do you create a smooth CSS hover transition?
How do you change the fade out effect on mouse over with CSS?
Videos
CSS Transitions don't work on display:block/none; You can manage to give that effect using visibility/opacity properties.
Check this example, You can manually add the transition-delay property if you really want it to add.
.main_div {
width: 100px;
height: 100px;
border: thin black solid;
position: relative;
}
.main_div .overlay_div {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
visibility: hidden;
opacity: 0;
transition: all 1s ease-out;
}
.main_div:hover .overlay_div {
visibility: visible;
opacity: 1;
transition: all 1s ease-in;
}
<div class="main_div">
<div class="overlay_div">
some text
</div>
</div>
Code work fine just change display from none to block, as transition doesn't works when changing display.
.main_div .overlay_div{
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
width:100%;
height:100%;
display:block;/*Change this*/
......
......
}
Nowadays people are just using CSS3 transitions because it's a lot easier than messing with JS, browser support is reasonably good and it's merely cosmetic so it doesn't matter if it doesn't work.
Something like this gets the job done:
a {
color:blue;
/* First we need to help some browsers along for this to work.
Just because a vendor prefix is there, doesn't mean it will
work in a browser made by that vendor either, it's just for
future-proofing purposes I guess. */
-o-transition:.5s;
-ms-transition:.5s;
-moz-transition:.5s;
-webkit-transition:.5s;
/* ...and now for the proper property */
transition:.5s;
}
a:hover { color:red; }
You can also transition specific CSS properties with different timings and easing functions by separating each declaration with a comma, like so:
a {
color:blue; background:white;
-o-transition:color .2s ease-out, background 1s ease-in;
-ms-transition:color .2s ease-out, background 1s ease-in;
-moz-transition:color .2s ease-out, background 1s ease-in;
-webkit-transition:color .2s ease-out, background 1s ease-in;
/* ...and now override with proper CSS property */
transition:color .2s ease-out, background 1s ease-in;
}
a:hover { color:red; background:yellow; }
Demo here
I know in the question you state "I assume JavaScript is used to create this effect" but CSS can be used too, an example is below.
CSS
.fancy-link {
color: #333333;
text-decoration: none;
transition: color 0.3s linear;
-webkit-transition: color 0.3s linear;
-moz-transition: color 0.3s linear;
}
.fancy-link:hover {
color: #F44336;
}
HTML
<a class="fancy-link" href="#">My Link</a>
And here is a JSFIDDLE for the above code!
Marcel in one of the answers points out you can "transition multiple CSS properties" you can also use "all" to effect the element with all your :hover styles like below.
CSS
.fancy-link {
color: #333333;
text-decoration: none;
transition: all 0.3s linear;
-webkit-transition: all 0.3s linear;
-moz-transition: all 0.3s linear;
}
.fancy-link:hover {
color: #F44336;
padding-left: 10px;
}
HTML
<a class="fancy-link" href="#">My Link</a>
And here is a JSFIDDLE for the "all" example!
This should work for you! http://jsfiddle.net/L7XCD/1/
Let's use the great mozilla documentation to explain this:
Transition rovide a way to control the speed of animation changes to CSS properties. Instead of having the animation changes take effect instantly, you can transition the property changes over a specified time period.
Also we used the transition timing functions (ease, linear, easy-in, easy-out, easy-in-out)
Timing functions determine how intermediate values of the transition are calculated. The timing function can be specified by providing the graph of the corresponding function, as defined by four points defining a cubic bezier
CCS markup:
img {
opacity: 0.6;
transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-webkit-transition: opacity 1s ease-in-out;
}
img:hover {
opacity: 1.0;
transition: opacity .55s ease-in-out;
-moz-transition: opacity .55s ease-in-out;
-webkit-transition: opacity .55s ease-in-out;
}
Since he was using the transition ease-in-out, I thought it was better to use the same transition function.
For more information, check the documentation here
Hope it helps!
http://jsfiddle.net/L7XCD/2/ Just add the transition effect to your element without the hover-tag
Usually I would just look it up but I genuinely dont know what to call this. Its a really common thing you see on a lot of sites sometimes where when you hover over an image a small bit of shade and text fades in at the bottom. More specifically, hover on the images on this site: https://www.midjourney.com/explore?tab=random to know what I'm talking about. I tried to inspect the code but it honestly looks so confusing to me and I have a feeling there's a simpler way to do it, I just have no idea how.
This might be a stupid question but my web dev classes only went over basic stuff, I know nothing about transitions and animations and stuff like that.