【发布时间】:2014-01-14 14:28:25
【问题描述】:
我有一个包含三个 div 的容器。每个 div 包含一个隐藏的 div,其中有一个“隐藏”类 (display:none;),当悬停在其父 div 上时应该显示该类。
我使用toggleClass('show') 使secretDiv 显示有一个块。将鼠标悬停在父 div 上时,我需要显示 secretDiv。
父 div 应该显示在下面的 div 之上,而不是推送其他 div
--- HTML ---
<div class="row">
<div class="element">
<img src="http://placehold.it/200x100" alt="" title="" />
<div class="secretDiv hide">
<p>Some secret text and stuff</p>
</div>
</div>
<div class="element">
<img src="http://placehold.it/200x100" alt="my image" title="image title" />
<div class="secretDiv hide">
<p>Some secret text and stuff</p>
</div>
</div>
</div>
<div class="row">
<div class="element">
<img src="http://placehold.it/200x100" alt="" title="" />
<div class="secretDiv hide">
<p>Some secret text and stuff</p>
</div>
</div>
<div class="element">
<img src="http://placehold.it/200x100" alt="my image" title="image title" />
<div class="secretDiv hide">
<p>Some secret text and stuff</p>
</div>
</div>
</div>
--- CSS ---
.hide {display:none;}
.show {display:block;}
.row {height:160px;background:#dedede;float:left;width:480px;position:relative:z-index:1;}
.row .element {position:relative;z-index:9;text-align:center; float:left; background:#666;width:200px;padding:12px;margin:6px;}
.row .image {}
.row .secretDiv {background:#ff0000;padding:8px;}
--- JS ---
$('.element').hover(function(){
$('.element .secretDiv').toggleClass('show');
});
【问题讨论】:
-
喜欢这个jsfiddle.net/j08691/2xLMQ/5?不知道你到底在追求什么。
-
那么问题是什么
-
或者像这样:jsfiddle.net/2xLMQ/7
标签: html css css-position z-index