2017-06-20 16 views
0

你可以看看這個演示,並讓我知道爲什麼我不能在.carousel上顯示.container不能用Z-Index覆蓋引導轉盤上的Div

正如你可以看到我嘗試設置的z-index兩個,但它不工作

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

回答

-1
.container{ 
position: relative; 
} 
0

這裏是一個多解...!你需要設置.box的位置爲absoluterelative它的父母......!

.container.box { 
 
\t position: absolute; 
 
\t background: rgba(255, 0, 0, 0.5); 
 
\t top: 0px; 
 
\t left: 0px; 
 
\t height: 100%; 
 
\t width: 100%; 
 
} 
 
.container {position: relative;} 
 
.carousel-control {z-index: 100;}
<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 row" 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>

如果需要使用左,右控制,那麼你需要在你的CSS添加.carousel-control {z-index: 100;} ....!