CSS Hover bug, overlay fluctuating effect on hover
I am trying to place one overlay div over another so that on hover on the card div displays overlay div above it. But on hover, I don't know why there is some bug which creates a fluctuating effect before displaying the overlay div.
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
/*display: inline-block;*/
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover + .overlay {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
<div class="card" style="background: #fff; height: 290px; width: 240px; border-radius: 30px; display: inline-block; margin:20px; box-shadow: 0 2px 6px rgba(112,112,112,0.2);"><img src="thumb.png" height="60%;"></div>
<div class="overlay"></div>
What am I doing wrong here?
html css
|
show 2 more comments
I am trying to place one overlay div over another so that on hover on the card div displays overlay div above it. But on hover, I don't know why there is some bug which creates a fluctuating effect before displaying the overlay div.
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
/*display: inline-block;*/
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover + .overlay {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
<div class="card" style="background: #fff; height: 290px; width: 240px; border-radius: 30px; display: inline-block; margin:20px; box-shadow: 0 2px 6px rgba(112,112,112,0.2);"><img src="thumb.png" height="60%;"></div>
<div class="overlay"></div>
What am I doing wrong here?
html css
1
I think it will work if you warp them and use theparent:hover > .overlay
instead of selecting the next element like you do now (Edit: Coli's answer is better)
– Alon Eitan
Nov 19 '18 at 13:19
1
The problem is that you are putting another element over your hovered element - which makes your mouse cursor now rest on this element, meaning the other one is not in its hover state any more … Make that overlay a descendant of the triggering element to avoid this. (Hovering a descendant element always automatically means hovering the ancestor as well.)
– misorude
Nov 19 '18 at 13:20
if you put your overlay inside the card, then you could position it absolutely to the card (therefore not needed the manual minus top) and this would solve your hover problem
– Pete
Nov 19 '18 at 13:28
1
here is an example - easier way to line up your overlay to be on top of the card too: jsfiddle.net/waxzes0j
– Pete
Nov 19 '18 at 13:34
@Pete why you don't post this as an answer?
– Coli
Nov 19 '18 at 13:44
|
show 2 more comments
I am trying to place one overlay div over another so that on hover on the card div displays overlay div above it. But on hover, I don't know why there is some bug which creates a fluctuating effect before displaying the overlay div.
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
/*display: inline-block;*/
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover + .overlay {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
<div class="card" style="background: #fff; height: 290px; width: 240px; border-radius: 30px; display: inline-block; margin:20px; box-shadow: 0 2px 6px rgba(112,112,112,0.2);"><img src="thumb.png" height="60%;"></div>
<div class="overlay"></div>
What am I doing wrong here?
html css
I am trying to place one overlay div over another so that on hover on the card div displays overlay div above it. But on hover, I don't know why there is some bug which creates a fluctuating effect before displaying the overlay div.
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
/*display: inline-block;*/
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover + .overlay {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
<div class="card" style="background: #fff; height: 290px; width: 240px; border-radius: 30px; display: inline-block; margin:20px; box-shadow: 0 2px 6px rgba(112,112,112,0.2);"><img src="thumb.png" height="60%;"></div>
<div class="overlay"></div>
What am I doing wrong here?
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
/*display: inline-block;*/
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover + .overlay {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
<div class="card" style="background: #fff; height: 290px; width: 240px; border-radius: 30px; display: inline-block; margin:20px; box-shadow: 0 2px 6px rgba(112,112,112,0.2);"><img src="thumb.png" height="60%;"></div>
<div class="overlay"></div>
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
/*display: inline-block;*/
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover + .overlay {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
<div class="card" style="background: #fff; height: 290px; width: 240px; border-radius: 30px; display: inline-block; margin:20px; box-shadow: 0 2px 6px rgba(112,112,112,0.2);"><img src="thumb.png" height="60%;"></div>
<div class="overlay"></div>
html css
html css
asked Nov 19 '18 at 13:17
SayamKSayamK
297
297
1
I think it will work if you warp them and use theparent:hover > .overlay
instead of selecting the next element like you do now (Edit: Coli's answer is better)
– Alon Eitan
Nov 19 '18 at 13:19
1
The problem is that you are putting another element over your hovered element - which makes your mouse cursor now rest on this element, meaning the other one is not in its hover state any more … Make that overlay a descendant of the triggering element to avoid this. (Hovering a descendant element always automatically means hovering the ancestor as well.)
– misorude
Nov 19 '18 at 13:20
if you put your overlay inside the card, then you could position it absolutely to the card (therefore not needed the manual minus top) and this would solve your hover problem
– Pete
Nov 19 '18 at 13:28
1
here is an example - easier way to line up your overlay to be on top of the card too: jsfiddle.net/waxzes0j
– Pete
Nov 19 '18 at 13:34
@Pete why you don't post this as an answer?
– Coli
Nov 19 '18 at 13:44
|
show 2 more comments
1
I think it will work if you warp them and use theparent:hover > .overlay
instead of selecting the next element like you do now (Edit: Coli's answer is better)
– Alon Eitan
Nov 19 '18 at 13:19
1
The problem is that you are putting another element over your hovered element - which makes your mouse cursor now rest on this element, meaning the other one is not in its hover state any more … Make that overlay a descendant of the triggering element to avoid this. (Hovering a descendant element always automatically means hovering the ancestor as well.)
– misorude
Nov 19 '18 at 13:20
if you put your overlay inside the card, then you could position it absolutely to the card (therefore not needed the manual minus top) and this would solve your hover problem
– Pete
Nov 19 '18 at 13:28
1
here is an example - easier way to line up your overlay to be on top of the card too: jsfiddle.net/waxzes0j
– Pete
Nov 19 '18 at 13:34
@Pete why you don't post this as an answer?
– Coli
Nov 19 '18 at 13:44
1
1
I think it will work if you warp them and use the
parent:hover > .overlay
instead of selecting the next element like you do now (Edit: Coli's answer is better)– Alon Eitan
Nov 19 '18 at 13:19
I think it will work if you warp them and use the
parent:hover > .overlay
instead of selecting the next element like you do now (Edit: Coli's answer is better)– Alon Eitan
Nov 19 '18 at 13:19
1
1
The problem is that you are putting another element over your hovered element - which makes your mouse cursor now rest on this element, meaning the other one is not in its hover state any more … Make that overlay a descendant of the triggering element to avoid this. (Hovering a descendant element always automatically means hovering the ancestor as well.)
– misorude
Nov 19 '18 at 13:20
The problem is that you are putting another element over your hovered element - which makes your mouse cursor now rest on this element, meaning the other one is not in its hover state any more … Make that overlay a descendant of the triggering element to avoid this. (Hovering a descendant element always automatically means hovering the ancestor as well.)
– misorude
Nov 19 '18 at 13:20
if you put your overlay inside the card, then you could position it absolutely to the card (therefore not needed the manual minus top) and this would solve your hover problem
– Pete
Nov 19 '18 at 13:28
if you put your overlay inside the card, then you could position it absolutely to the card (therefore not needed the manual minus top) and this would solve your hover problem
– Pete
Nov 19 '18 at 13:28
1
1
here is an example - easier way to line up your overlay to be on top of the card too: jsfiddle.net/waxzes0j
– Pete
Nov 19 '18 at 13:34
here is an example - easier way to line up your overlay to be on top of the card too: jsfiddle.net/waxzes0j
– Pete
Nov 19 '18 at 13:34
@Pete why you don't post this as an answer?
– Coli
Nov 19 '18 at 13:44
@Pete why you don't post this as an answer?
– Coli
Nov 19 '18 at 13:44
|
show 2 more comments
2 Answers
2
active
oldest
votes
That's because the z-index
of the overlay increases by hovering the .card
. But now you no longer hovering the .card
, you are hovering the .overlay
and so it disappears.
To fix this, you should add a .overlay:hover
style too:
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
/*display: inline-block;*/
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover + .overlay, .overlay:hover {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
<div class="card" style="background: #fff; height: 290px; width: 240px; border-radius: 30px; display: inline-block; margin:20px; box-shadow: 0 2px 6px rgba(112,112,112,0.2);"><img src="thumb.png" height="60%;"></div>
<div class="overlay"></div>
add a comment |
Another idea is to prevent the overlay from catching events (hover in this case) by using pointer-events: none;
so that you don't lose the initial hover applied to the card:
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
pointer-events: none;
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover+.overlay {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
.card {
background: red;
height: 290px;
width: 240px;
border-radius: 30px;
display: inline-block;
margin: 20px;
box-shadow: 0 2px 6px rgba(112, 112, 112, 0.2);
}
<div class="card"></div>
<div class="overlay"></div>
You can also simplify your code using pseudo element:
.card:before {
content:"";
position: absolute;
opacity: 0;
z-index: -2;
top:20px;
right:20px;
left:-20px;
bottom:-20px;
background: #000;
border-radius: 30px;
pointer-events: none;
transition: all .4s ease;
}
.card:hover::before {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
.card {
position:relative;
background: red;
height: 290px;
width: 240px;
border-radius: 30px;
display: inline-block;
margin: 20px;
box-shadow: 0 2px 6px rgba(112, 112, 112, 0.2);
}
<div class="card"></div>
Nice solution too. But you should mention, that every content on.overlay
isn't clickable then.
– Coli
Nov 19 '18 at 13:43
1
@coli already said: to prevent the overlay from catching events
– Temani Afif
Nov 19 '18 at 13:47
I don't think that's clear enough to understand that you can't click links on it anymore.
– Coli
Nov 19 '18 at 13:49
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375486%2fcss-hover-bug-overlay-fluctuating-effect-on-hover%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
That's because the z-index
of the overlay increases by hovering the .card
. But now you no longer hovering the .card
, you are hovering the .overlay
and so it disappears.
To fix this, you should add a .overlay:hover
style too:
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
/*display: inline-block;*/
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover + .overlay, .overlay:hover {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
<div class="card" style="background: #fff; height: 290px; width: 240px; border-radius: 30px; display: inline-block; margin:20px; box-shadow: 0 2px 6px rgba(112,112,112,0.2);"><img src="thumb.png" height="60%;"></div>
<div class="overlay"></div>
add a comment |
That's because the z-index
of the overlay increases by hovering the .card
. But now you no longer hovering the .card
, you are hovering the .overlay
and so it disappears.
To fix this, you should add a .overlay:hover
style too:
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
/*display: inline-block;*/
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover + .overlay, .overlay:hover {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
<div class="card" style="background: #fff; height: 290px; width: 240px; border-radius: 30px; display: inline-block; margin:20px; box-shadow: 0 2px 6px rgba(112,112,112,0.2);"><img src="thumb.png" height="60%;"></div>
<div class="overlay"></div>
add a comment |
That's because the z-index
of the overlay increases by hovering the .card
. But now you no longer hovering the .card
, you are hovering the .overlay
and so it disappears.
To fix this, you should add a .overlay:hover
style too:
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
/*display: inline-block;*/
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover + .overlay, .overlay:hover {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
<div class="card" style="background: #fff; height: 290px; width: 240px; border-radius: 30px; display: inline-block; margin:20px; box-shadow: 0 2px 6px rgba(112,112,112,0.2);"><img src="thumb.png" height="60%;"></div>
<div class="overlay"></div>
That's because the z-index
of the overlay increases by hovering the .card
. But now you no longer hovering the .card
, you are hovering the .overlay
and so it disappears.
To fix this, you should add a .overlay:hover
style too:
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
/*display: inline-block;*/
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover + .overlay, .overlay:hover {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
<div class="card" style="background: #fff; height: 290px; width: 240px; border-radius: 30px; display: inline-block; margin:20px; box-shadow: 0 2px 6px rgba(112,112,112,0.2);"><img src="thumb.png" height="60%;"></div>
<div class="overlay"></div>
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
/*display: inline-block;*/
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover + .overlay, .overlay:hover {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
<div class="card" style="background: #fff; height: 290px; width: 240px; border-radius: 30px; display: inline-block; margin:20px; box-shadow: 0 2px 6px rgba(112,112,112,0.2);"><img src="thumb.png" height="60%;"></div>
<div class="overlay"></div>
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
/*display: inline-block;*/
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover + .overlay, .overlay:hover {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
<div class="card" style="background: #fff; height: 290px; width: 240px; border-radius: 30px; display: inline-block; margin:20px; box-shadow: 0 2px 6px rgba(112,112,112,0.2);"><img src="thumb.png" height="60%;"></div>
<div class="overlay"></div>
edited Nov 19 '18 at 13:27
answered Nov 19 '18 at 13:21
ColiColi
372214
372214
add a comment |
add a comment |
Another idea is to prevent the overlay from catching events (hover in this case) by using pointer-events: none;
so that you don't lose the initial hover applied to the card:
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
pointer-events: none;
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover+.overlay {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
.card {
background: red;
height: 290px;
width: 240px;
border-radius: 30px;
display: inline-block;
margin: 20px;
box-shadow: 0 2px 6px rgba(112, 112, 112, 0.2);
}
<div class="card"></div>
<div class="overlay"></div>
You can also simplify your code using pseudo element:
.card:before {
content:"";
position: absolute;
opacity: 0;
z-index: -2;
top:20px;
right:20px;
left:-20px;
bottom:-20px;
background: #000;
border-radius: 30px;
pointer-events: none;
transition: all .4s ease;
}
.card:hover::before {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
.card {
position:relative;
background: red;
height: 290px;
width: 240px;
border-radius: 30px;
display: inline-block;
margin: 20px;
box-shadow: 0 2px 6px rgba(112, 112, 112, 0.2);
}
<div class="card"></div>
Nice solution too. But you should mention, that every content on.overlay
isn't clickable then.
– Coli
Nov 19 '18 at 13:43
1
@coli already said: to prevent the overlay from catching events
– Temani Afif
Nov 19 '18 at 13:47
I don't think that's clear enough to understand that you can't click links on it anymore.
– Coli
Nov 19 '18 at 13:49
add a comment |
Another idea is to prevent the overlay from catching events (hover in this case) by using pointer-events: none;
so that you don't lose the initial hover applied to the card:
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
pointer-events: none;
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover+.overlay {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
.card {
background: red;
height: 290px;
width: 240px;
border-radius: 30px;
display: inline-block;
margin: 20px;
box-shadow: 0 2px 6px rgba(112, 112, 112, 0.2);
}
<div class="card"></div>
<div class="overlay"></div>
You can also simplify your code using pseudo element:
.card:before {
content:"";
position: absolute;
opacity: 0;
z-index: -2;
top:20px;
right:20px;
left:-20px;
bottom:-20px;
background: #000;
border-radius: 30px;
pointer-events: none;
transition: all .4s ease;
}
.card:hover::before {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
.card {
position:relative;
background: red;
height: 290px;
width: 240px;
border-radius: 30px;
display: inline-block;
margin: 20px;
box-shadow: 0 2px 6px rgba(112, 112, 112, 0.2);
}
<div class="card"></div>
Nice solution too. But you should mention, that every content on.overlay
isn't clickable then.
– Coli
Nov 19 '18 at 13:43
1
@coli already said: to prevent the overlay from catching events
– Temani Afif
Nov 19 '18 at 13:47
I don't think that's clear enough to understand that you can't click links on it anymore.
– Coli
Nov 19 '18 at 13:49
add a comment |
Another idea is to prevent the overlay from catching events (hover in this case) by using pointer-events: none;
so that you don't lose the initial hover applied to the card:
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
pointer-events: none;
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover+.overlay {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
.card {
background: red;
height: 290px;
width: 240px;
border-radius: 30px;
display: inline-block;
margin: 20px;
box-shadow: 0 2px 6px rgba(112, 112, 112, 0.2);
}
<div class="card"></div>
<div class="overlay"></div>
You can also simplify your code using pseudo element:
.card:before {
content:"";
position: absolute;
opacity: 0;
z-index: -2;
top:20px;
right:20px;
left:-20px;
bottom:-20px;
background: #000;
border-radius: 30px;
pointer-events: none;
transition: all .4s ease;
}
.card:hover::before {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
.card {
position:relative;
background: red;
height: 290px;
width: 240px;
border-radius: 30px;
display: inline-block;
margin: 20px;
box-shadow: 0 2px 6px rgba(112, 112, 112, 0.2);
}
<div class="card"></div>
Another idea is to prevent the overlay from catching events (hover in this case) by using pointer-events: none;
so that you don't lose the initial hover applied to the card:
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
pointer-events: none;
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover+.overlay {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
.card {
background: red;
height: 290px;
width: 240px;
border-radius: 30px;
display: inline-block;
margin: 20px;
box-shadow: 0 2px 6px rgba(112, 112, 112, 0.2);
}
<div class="card"></div>
<div class="overlay"></div>
You can also simplify your code using pseudo element:
.card:before {
content:"";
position: absolute;
opacity: 0;
z-index: -2;
top:20px;
right:20px;
left:-20px;
bottom:-20px;
background: #000;
border-radius: 30px;
pointer-events: none;
transition: all .4s ease;
}
.card:hover::before {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
.card {
position:relative;
background: red;
height: 290px;
width: 240px;
border-radius: 30px;
display: inline-block;
margin: 20px;
box-shadow: 0 2px 6px rgba(112, 112, 112, 0.2);
}
<div class="card"></div>
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
pointer-events: none;
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover+.overlay {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
.card {
background: red;
height: 290px;
width: 240px;
border-radius: 30px;
display: inline-block;
margin: 20px;
box-shadow: 0 2px 6px rgba(112, 112, 112, 0.2);
}
<div class="card"></div>
<div class="overlay"></div>
.overlay {
opacity: 0;
z-index: -2;
height: 290px;
width: 240px;
background: #000;
border-radius: 30px;
pointer-events: none;
position: relative;
top: -310px;
transition: all .4s ease;
}
.card:hover+.overlay {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
.card {
background: red;
height: 290px;
width: 240px;
border-radius: 30px;
display: inline-block;
margin: 20px;
box-shadow: 0 2px 6px rgba(112, 112, 112, 0.2);
}
<div class="card"></div>
<div class="overlay"></div>
.card:before {
content:"";
position: absolute;
opacity: 0;
z-index: -2;
top:20px;
right:20px;
left:-20px;
bottom:-20px;
background: #000;
border-radius: 30px;
pointer-events: none;
transition: all .4s ease;
}
.card:hover::before {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
.card {
position:relative;
background: red;
height: 290px;
width: 240px;
border-radius: 30px;
display: inline-block;
margin: 20px;
box-shadow: 0 2px 6px rgba(112, 112, 112, 0.2);
}
<div class="card"></div>
.card:before {
content:"";
position: absolute;
opacity: 0;
z-index: -2;
top:20px;
right:20px;
left:-20px;
bottom:-20px;
background: #000;
border-radius: 30px;
pointer-events: none;
transition: all .4s ease;
}
.card:hover::before {
opacity: 1;
z-index: 1;
transition: all .4s ease;
}
.card {
position:relative;
background: red;
height: 290px;
width: 240px;
border-radius: 30px;
display: inline-block;
margin: 20px;
box-shadow: 0 2px 6px rgba(112, 112, 112, 0.2);
}
<div class="card"></div>
edited Nov 19 '18 at 13:46
answered Nov 19 '18 at 13:39
Temani AfifTemani Afif
72.9k94081
72.9k94081
Nice solution too. But you should mention, that every content on.overlay
isn't clickable then.
– Coli
Nov 19 '18 at 13:43
1
@coli already said: to prevent the overlay from catching events
– Temani Afif
Nov 19 '18 at 13:47
I don't think that's clear enough to understand that you can't click links on it anymore.
– Coli
Nov 19 '18 at 13:49
add a comment |
Nice solution too. But you should mention, that every content on.overlay
isn't clickable then.
– Coli
Nov 19 '18 at 13:43
1
@coli already said: to prevent the overlay from catching events
– Temani Afif
Nov 19 '18 at 13:47
I don't think that's clear enough to understand that you can't click links on it anymore.
– Coli
Nov 19 '18 at 13:49
Nice solution too. But you should mention, that every content on
.overlay
isn't clickable then.– Coli
Nov 19 '18 at 13:43
Nice solution too. But you should mention, that every content on
.overlay
isn't clickable then.– Coli
Nov 19 '18 at 13:43
1
1
@coli already said: to prevent the overlay from catching events
– Temani Afif
Nov 19 '18 at 13:47
@coli already said: to prevent the overlay from catching events
– Temani Afif
Nov 19 '18 at 13:47
I don't think that's clear enough to understand that you can't click links on it anymore.
– Coli
Nov 19 '18 at 13:49
I don't think that's clear enough to understand that you can't click links on it anymore.
– Coli
Nov 19 '18 at 13:49
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375486%2fcss-hover-bug-overlay-fluctuating-effect-on-hover%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I think it will work if you warp them and use the
parent:hover > .overlay
instead of selecting the next element like you do now (Edit: Coli's answer is better)– Alon Eitan
Nov 19 '18 at 13:19
1
The problem is that you are putting another element over your hovered element - which makes your mouse cursor now rest on this element, meaning the other one is not in its hover state any more … Make that overlay a descendant of the triggering element to avoid this. (Hovering a descendant element always automatically means hovering the ancestor as well.)
– misorude
Nov 19 '18 at 13:20
if you put your overlay inside the card, then you could position it absolutely to the card (therefore not needed the manual minus top) and this would solve your hover problem
– Pete
Nov 19 '18 at 13:28
1
here is an example - easier way to line up your overlay to be on top of the card too: jsfiddle.net/waxzes0j
– Pete
Nov 19 '18 at 13:34
@Pete why you don't post this as an answer?
– Coli
Nov 19 '18 at 13:44