我开始学习 css 和 html,在我的网站上我制作了一个横幅,如下所示:
我想知道是否可以采用我制作的这个示例并将其转换为带有最多 3 个图像的 slider 的横幅,如下所示:
我想仅用css是不可能的,但我对javascript一无所知,我尝试了很多 slider 教程,但没有一个看起来像我想要的那样,即宽度为100%的横幅。
有人可以帮我将第一张图片转换为第二张图片吗?
我的代码:
html: <div id="banner" class="banner"></div>
CSS:
.banner {
width: 100%;
height: 400px;
margin-top: -20px;
background: url("http://s2.postimg.org/vtiiv9maf/index_banner.jpg");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
jsfiddle 我的代码示例:https://jsfiddle.net/wykknyqf/
最佳答案
为什么不直接使用 Bootstrap Carousel? http://jsfiddle.net/mm6ck3dc/5/
HTML
<br>
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="http://lorempixel.com/400/200/sports/" alt="Chania" height="345">
</div>
<div class="item">
<img src="http://lorempixel.com/400/200/sports/" alt="Chania" height="345">
</div>
<div class="item">
<img src="http://lorempixel.com/400/200/sports/" alt="Flower" height="345">
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" 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="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
CSS
body{margin: 0;}
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
width: 100%;
margin: auto;
}
关于javascript - CSS 横幅 slider ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34323193/