Search code examples
twitter-bootstrapcsstwitter-bootstrap-3z-index

Not Able to Overlay a Div on Bootstrap carousel With Z-Index


Can you please take a look at this demo and let me know why I am not able to display the .container over the .carousel ?

As you can see I tried to set the z-index on both but it is not working

.box {
  background-color: red;
  margin-top: -20px;
  border-top: 5px solid #29aae3;
  min-height: 80px;
  z-index: 50;
}
.carousel{z-index:10;} 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="container">
  <div id="carousel-example-generic" class="carousel slide" data-ride="carousel" style="">
    <!-- Indicators -->
    <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>

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">
      <div class="item active">
        <img src="http://via.placeholder.com/1920x350" alt="...">
        <div class="carousel-caption">
          ...
        </div>
      </div>

    </div>

    <!-- Controls -->
    <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left" 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="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>

  <div class="container box">  </div>

</div>


Solution

  • .container{
    position: relative;
    }