How to show hidden content when hover in CSS

跟風遠走 提交于 2019-12-12 06:58:54

问题


As the title says I want to show a hidden span "box" when hovering an image, but I can't get it to work, so I was hoping you guys could figure out my mistake.

HTML

<span class="DDAA__bg">
<h1 class="DDAA__headline"><a href="#">DANSK DYREVÆRN ÅRHUS</a></h1>
</span>
<span class="DDAA__pic">
<img src="img/DDAA-Logo.png" width="980" height="200"  alt="Dansk Dyreværn Århus"/>
</span>

CSS

span.DDAA__bg{
  height: 200px;
  width: 980px;
  background-color: #666;
  position: absolute;
  display: none;
}

span.DDAA__pic{
   display:block;
   visibility: visible;
}

span.DDAA__pic:hover{
   visibility: hidden;
   transition-delay: 2s;
}

span.DDAA__pic:hover + span.DDAA__bg{
   display:block;
}

You can see here how it works now, not as good :/

http://jsfiddle.net/ary3bt83/3/


回答1:


element:hover > other_element {
 display: block;
}

this is equal to the jQuery code

 $(element).on('hover', function() { $(this).css("display", "block"); });

But doing hover on css sometimes is really buggy...




回答2:


First you need to have jQuery installed ( look for jquery.js / jquery.min.js in source code or google for w3c jquery install )

After this you write following :

<script>
$(document).ready(function() {
// everything here is done once the page is loaded

// define hover event handler for a specific element
$(".the_hovered_element").on('hover', function() {
   // show the element 
   $(".the_element_to_be_shown").css("display","block");
});
});
</script>

Don't forget that you must initially set display: none to the div that is first hidden and then shown. Also instead of .css("display","block") you can have simple animation like .fadeIn("slow");



来源:https://stackoverflow.com/questions/26318894/how-to-show-hidden-content-when-hover-in-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!