Bootstrap图片轮播组件Carousel使用方法详解(2)

<head> <!--声明网页编码,自动适应浏览器的尺寸,要使用bootstrap的css,需要jquery支持,要使用bootstrap的js,标题--> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta content="width=device-width,initial-scale=1.0,user-scalable=no"> <link href="https://www.jb51.net/css/bootstrap.css" media="screen"> <script type="text/javascript" src="https://www.jb51.net/js/jquery-1.11.1.js"></script> <script type="text/javascript" src="https://www.jb51.net/js/bootstrap.js"></script> <title>图片轮播Carousel</title> </head>

(2)<body>部分

先声明一个容器container,这个容器能使网页的所有元素自动归于网页中央,之后在这个容器中编写元素。

首先编写页头,声明一个页头,之后其里面写入一段文本。

<div> <h1> 图片轮播Carousel </h1> </div>

之后定义一个未命名的图层div,主要是用来规范图片轮播组件用的。bootstrap的图片轮播组件大小不能对其里面的元素,加入width与height参数进行规定。这样图片轮播组件会失真。同时这个组件要居中,必须在div的style属性中使用margin-right: auto; margin-left: auto;来约束,额外加入align="center"是根本一点效果都没有。

最后是图片组件各部分的详细说明:

<div> <!--图片轮播组件的名称为carousel,data-ride元素是bootstrap要求存在的,data-interval的值是每隔1000毫秒,也就是1秒换一张图片,此值太小组件会失真--> <div data-ride="carousel" data-interval="1000"> <!--这里定义有几张图片,如果再多一张图片就再下面多加一项,data-slide-to的值加一,首张图片也就是第0张图片必须要有class="active"否则组件无法工作--> <ol> <li data-target="#carousel-example-generic" data-slide-to="0"></li> <li data-target="#carousel-example-generic" data-slide-to="1"></li> <li data-target="#carousel-example-generic" data-slide-to="2"></li> </ol> <div role="listbox"> <!--以下是各张的图片的详细编辑,首张图片的class值必须为item active,余下的皆为item--> <div> <!--意为点击img0.jpg这张图片就打开img0.jpg的超级链接,如果不需要超级链接,则去掉<a>标签--> <a href="https://www.jb51.net/images/img0.jpg"><img src="https://www.jb51.net/images/img0.jpg" alt="img0"></a> <div> <!--图片下的文字说明--> <h3> img0 </h3> <p> 我是img0的图片说明 </p> </div> </div> <div> <a href="https://www.jb51.net/images/img10.jpg"><img src="https://www.jb51.net/images/img10.jpg" alt="img10"></a> <div> <h3> img10 </h3> <p> 我是img10的图片说明 </p> </div> </div> <div> <a href="https://www.jb51.net/images/img2.jpg"><img src="https://www.jb51.net/images/img2.jpg" alt="img2"></a> <div> <h3> img2 </h3> <p> 我是img2的图片说明 </p> </div> </div> </div> <!--这里是组件中向左想右的两个按钮,固定存在的框架代码--> <a href="#carousel-example-generic" role="button" data-slide="prev"> <span></span> </a> <a href="#carousel-example-generic" role="button" data-slide="next"> <span></span> </a> </div> </div>

精彩专题分享:

如果大家还想深入学习,可以点击这里进行学习,再为大家附3个精彩的专题:

Bootstrap学习教程

Bootstrap实战教程

Bootstrap Table使用教程

Bootstrap插件使用教程

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjxydg.html