我有这个代码,它是一个bootstrap轮播,我希望它在我悬停“#caroussel”时显示类“.carousel-indicators”(导航按钮)。
为此,我确实添加了一些不透明度参数,所以当我悬停“#caroussel”时,它将从0传递到1以便可见,这暂时不起作用。
body {
margin: 0;
}
.carousel-indicators li {
width: 20px;
height: 20px;
border-radius: 100%;
border: 3px solid white;
color: grey;
}
.carousel-indicators .active {
width: 20px;
height: 20px;
border-radius: 100%;
border: 3px solid black;
}
.carousel-indicators {
opacity: 0;
}
#caroussel:hover,
#caroussel:hover~.carousel-indicators {
opacity: 1;
}
<!--BS CSS-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!--BS JS-->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<div id="caroussel">
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="https://fyf.tac-cdn.net/images/products/large/BF116-11KM.jpg" alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="https://04dc27fa9cbd58cbea8c-bbb0d8e518ac050fae1d74ee0f9c6cec.ssl.cf4.rackcdn.com/images/products/340x397/29.jpg" alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="https://cdn.bloomnation.com/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/2/0/20140701073819_file_53b30e2b2de3f_56.jpeg" alt="Third slide">
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
感谢大家。
你使用了错误的选择器; ~
是general sibling selector。由于.carousel-indicators
是#caroussel
的子元素,这应该是你需要的所有(使用descendant selector):
#caroussel:hover .carousel-indicators
{
opacity: 1;
}
试试这个代码。
.carousel-indicators {
-webkit-transition: all 0.5s linear;
-moz-transition: all 0.5s linear;
-ms-transition: all 0.5s linear;
-o-transition: all 0.5s linear;
transition: all 0.5s linear;
opacity: 0;
}
#carousel:hover .carousel-indicators {
opacity: 1;
}