我有这段代码是一个引导式转盘,当我将鼠标悬停在“ #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;
}