Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a div disappear on hover without it flickering when the mouse moves?

I've seen answers suggesting just display:none on the :hover css. But that makes the div flicker when the mouse is moving.

EDIT: Added jsfiddle

like image 212
aph Avatar asked Apr 30 '11 21:04

aph


People also ask

How do I hide something on hover?

You can do this by using the :hover property of a page element. For example, if we have a div inside another div, we can check the hover of the outer div to show/hide the inner div. This CSS hides the inner div by default using "display: none;".

How do you make a Div visible on hover?

To display div element using CSS on hover a tag: First, set the div element invisible i.e display:none;. By using the adjacent sibling selector and hover on a tag to display the div element.

Can we hover with mouse?

Hovering is a fundamental digital action that involves placing the mouse cursor on the target link or button. Users mainly use the mouse hover action to access sub-menu items.

Why Hover is not working on div?

You might have linked your stylesheet to your HTML file improperly. Some other CSS in the context of your project may be overriding the piece that you've given here. You might be running into browser compatibility issues with the :hover selector or something else in your code that is breaking the styling.


1 Answers

display:none will take the element out of the render tree, so it loses :hover state immediately, then reappears and gets :hover again, disappears, reappears, etc...

What you need is:

#elem { opacity:0; filter:alpha(opacity=0); }

It will leave the place empty, so no flickering will appear. (Demo or yours updated)

like image 183
25 revs, 4 users 83% Avatar answered Sep 26 '22 02:09

25 revs, 4 users 83%