Kathryn Crawford Kathryn Crawford - 3 months ago 92
CSS Question

Slick slider text on top of images

I'm trying to make a pretty normal carousel, with two arrows on either side in the vertical middle, and text with a button in the middle on top of the image. I cannot get anything to appear on top of the image though, even though the arrows and text are all absolute and have a higher z-index. Here's a codepen with my code. http://codepen.io/kathryncrawford/pen/AXmVAz

And here's my 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>


My CSS (the slick css is not included here, but it is in the codepen)

.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;
}


And my 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
});
});

Answer

You have to do

.slick-slide {
    /* ... */
    position: relative;
}

so that the .info stuff knows it should be absolutely positioned to it's parent.