我正在創建幻燈片,並且正在嘗試將其導航按鈕垂直居中放置在圖像上方。我嘗試使用頂端:50%,但它相對於按鈕的高度移動,而不是幻燈片的高度。我正在使用jQuery Cycle。將元素置於其父元素中
<div class="slideshow_container">
<h2>Amor Insecta</h2>
<div class="slideshow_controls">
<div class="cycle_prev"> </div>
<div class="cycle_next"> </div>
</div>
<div class="slideshow">
<img title="stylepageart2.jpg" src="http://cmpltunknwn.mybigcommerce.com/product_images/uploaded_images/stylepageart21.jpg" alt="stylepageart2.jpg" />
<img title="stylepageart3.jpg" src="http://cmpltunknwn.mybigcommerce.com/product_images/uploaded_images/stylepageart22.jpg" alt="stylepageart3.jpg" />
</div>
</div>
.slideshow_container {
width:90%;
margin: 0 auto 50px auto;
max-height:2000px;
}
.slideshow {
position: relative;
width: 100% !important;
}
.slideshow img {
width: 100% !important;
height:auto !important;
position: absolute;
top: 0;
left: 0;
}
.slideshow_controls {
display:none;
width:100%;
height:100%;
position:relative;
z-index:100!important;
}
.cycle_prev, .cycle_next {
position:absolute;
top:50%;
width:37px;
height:37px;
}
.cycle_prev{
left:0;
background:url(http://cmpltunknwn.mybigcommerce.com/product_images/theme_images/prev.jpg) no-repeat;
}
.cycle_next {
right:0;
background:url(http://cmpltunknwn.mybigcommerce.com/product_images/theme_images/next.jpg) no-repeat;
}
的問題是,你的元素被定位爲絕對元素。因此他們沒有得到可用的高度。我的建議:計算你的願望的高度,並用JavaScript設置它。那麼它會容易得多。 – KittMedia
@KittMedia:請問你能給我提供關於怎麼做的任何線索嗎? –
最簡單的方法是在這種情況下'$('img')。height();'。 – KittMedia