I need to show a div when you house over its parent (default is for the child div to be hidden). Is the only way to do this with javascript? Thanks
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Using jQuery you can add a
mouseover
event to the parent div, andshow
the child div. See this fiddle as an example.@jdln; yes
css:
check the fiddle: http://jsfiddle.net/sandeep/XLTV3/1/
I initially was using css solution above, but had to use jQuery because my child div contained an image which caused hover to flicker. Here we're displaying child when hovering over parent (if desktop screen size) on mouseenter and hiding it on mouseleave but only if now hovering over main page container, to minimize flickering:
In addition to the accepted answer, one can use
opacity
so that layout is not jumping around on hover (this also allows to animate the appearance):css:
html:
With jQuery, absolutely:
No JS required.