我有一個容器有三個div。每個div都包含一個隱藏的div,該隱藏的div有一個'hide'類(display:none;
),其內部應該顯示在其父div上。我使用toggleClass('show')
,使secretDiv顯示有一個塊。我需要secretDiv在鼠標懸停在父div上時顯示。CSS定位div與Z指數頂部
父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');
});
像這樣http://jsfiddle.net/j08691/2xLMQ/5/?不知道你到底是什麼。 – j08691
那麼問題是什麼 –
或者像這樣:http://jsfiddle.net/2xLMQ/7/ – putvande