java4ever java4ever - 3 months ago 17
CSS Question

Bootstrap v4.0.3 Alpha Carousel Shadow

Aloha,

I'm working (still) on the bootstrap website and want to apply a (inset!) shadow to the carousel.
HTML looks like this:

<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img src="..." alt="First slide">
</div>
<div class="carousel-item">
<img src="..." alt="Second slide">
</div>
<div class="carousel-item">
<img src="..." alt="Third slide">
</div>
</div>
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="icon-prev" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="icon-next" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>


Tried to apply via

.carousel-item {
box-shadow: inset 0 0 20rem rgba(0,0,0,1);

}
.carousel-item img {
z-index: -1;
}


(and a few others which did not work).

Anybody got an idea how to fix this?

Answer

The image is hiding the shadow. Use a pseudo element with the box-shadow instead..

.carousel-item:before {
    -webkit-box-shadow: inset 0 0 20rem rgba(0, 0, 0, 1);
    box-shadow: inset 0 0 20rem rgba(0, 0, 0, 1);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    content: "";
}

Codeply Demo

Comments