我正在尝试制作一个非常普通的旋转木马,在垂直中间的两侧各有两个箭头,在图像顶部的中间有一个按钮的文本。尽管箭头和文本都是绝对的并且具有更高的 z-index,但我无法在图像顶部显示任何内容。这是我的代码的代码笔。 http://codepen.io/kathryncrawford/pen/AXmVAz
这是我的 HTML
<div class="slick-slider">
<div>
<img class="img-fluid" src="http://www.placecage.com/1500/750" alt="">
<div class="info">
<h1 class="slider-heading">Heading</h1>
<p class="slider-subheading lead">Subheading</p>
<a class="btn btn-large btn-danger" href="">button text</a>
<p class="down-arrow">
<a class="btn btn-large btn-down-arrow" href="#theend">
<i class="fa fa-chevron-down fa-lg" aria-hidden="true"></i>
</a>
</p>
</div>
</div>
<div>
<img class="img-fluid" src="http://www.placecage.com/1500/750" alt="">
</div>
<div>
<img class="img-fluid" src="http://www.placecage.com/1500/750" alt="">
</div>
</div>
我的 CSS(漂亮的 CSS 没有包含在这里,但它在代码笔中)
.slick-slider img { /* keep images full screen */
width: 100%;
}
.chevron-container { /* full slider height container for chevrons */
height: 100%;
position: absolute;
width: 100px;
}
.slick-right { /* keeps right arrow to the right */
right: 0;
top: 0;
}
.chevron-container > .fa { /* positions chevrons in vertical center */
bottom: 0;
color: white;
font-size: 10em;
height: 1em;
margin: auto;
position: absolute;
top: 0;
width: 5em;
z-index: 10;
}
.slick-slider .info {
color: white;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
line-height: 100vh;
text-align: center;
z-index: 10;
}
.slick-slider .info > div {
display: inline-block !important;
vertical-align: middle;
}
还有我的JS
jQuery(function($){
$('.slick-slider').slick({
accessibility: true,
adaptiveHeight: true,
arrows: true,
infinite: true,
mobileFirst: true,
nextArrow: '<div class="chevron-container slick-right"><i class="fa fa-chevron-right" aria-hidden="true"></i></span><span class="sr-only">Next</span></div>',
prevArrow: '<div class="chevron-container"><i class="fa fa-chevron-left" aria-hidden="true"></i></span><span class="sr-only">Previous</span></div>',
slidesToShow: 1
});
});
最佳答案
你必须做
.slick-slide {
/* ... */
position: relative;
}
这样 .info
就知道它应该绝对定位到它的父级。
关于javascript - 图像顶部的光滑 slider 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38853757/