Reputation: 634
The following hides the element, but I cannot recover when I hover over it. I've checked devtools to see that it is indeed rendered on the screen, I just can't see the contents of the div.
How do I make it so the div is visible only on hover?
.visible-on-hover {
visibility: hidden;
}
.visible-on-hover:hover {
visibility: visible !important;
}
Upvotes: 0
Views: 73
Reputation: 56744
Elements with visibility: hidden;
don't receive any mouse events, so :hover
never triggers on such an element.
Instead of visibility
, you can work with opacity
:
div {
background-color: orange;
height: 200px;
width: 400px;
padding: 50px;
}
.visible-on-hover {
opacity: 0;
transition: opacity .3s ease;
}
.visible-on-hover:hover {
opacity: 1;
}
<div class="visible-on-hover">visible only on hover</div>
Upvotes: 2
Reputation:
you can not hover, focus or select a hidden element.
you can use opacity
.visible-on-hover {
opacity: 0;
}
.visible-on-hover:hover {
opacity: 1;
}
Upvotes: 1