java4ever java4ever - 1 year ago 163
CSS Question

Bootstrap v4.0.3 Alpha Carousel Shadow


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>
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img src="..." alt="First slide">
<div class="carousel-item">
<img src="..." alt="Second slide">
<div class="carousel-item">
<img src="..." alt="Third slide">
<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 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>

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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download