标题 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <h1 > h1. Bootstrap heading</h1 > <h2 > h2. Bootstrap heading</h2 > <h3 > h3. Bootstrap heading</h3 > <h4 > h4. Bootstrap heading</h4 > <h5 > h5. Bootstrap heading</h5 > <h6 > h6. Bootstrap heading</h6 > <br > <p class ="h1" > 文本尝试(Text Try)</p > <p class ="h2" > 文本尝试(Text Try)</p > <p class ="h3" > 文本尝试(Text Try)</p > <p class ="h4" > 文本尝试(Text Try)</p > <p class ="h5" > 文本尝试(Text Try)</p > <p class ="h6" > 文本尝试(Text Try)</p >
Bootstrap对默认的样式也做了优化。
这里的这两种效果是完全一样的看起来,不过还是建议使用
的这种方式,因为比如百度抓取标题关键词的时候是只会抓取h1里面的而不会抓取p标签里面的。
副标题 1 2 3 4 <p class ="h1" > 文本尝试 <small class ="text-muted" > (Text Try)</small > </p >
这里small就是副标题,加上一个text-muted类让它的颜色改变,显得更像副标题。
中心内容 1 2 3 4 5 6 7 8 <p > Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Duis mollis, est non commodo luctus. </p > <p class ="lead" > Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Duis mollis, est non commodo luctus. </p >
lead类定义一个中心文本,也就是比较显眼的文本。可以看到下面加了lead的和上面的不同。
语义化标签 比如这种,有很多。不再一一列举。
1 2 3 <p > <code > Java</code > 是一杯咖啡。 </p >
图片 略缩图 1 2 3 4 5 <body style ="padding: 100px" > <img src ="img/miaonei.jpg" alt ="喵内噶" class ="img-thumbnail" >
这里给body加了个边距,然后显示出来。
PS: 翻译 thumbnin:“指甲,极小的东西”
img-thumbnain:有圆角,边框,响应式。
这里Bootstrap里的响应式和普通的%宽度还不太一样。Bootstrap的类的响应式是只有屏幕小到一定程度之后才触发;而%的响应式是随时都会变,屏幕变大一点图片就变大一点。
普通图片 1 <img src ="img/halu.jpg" alt ="哈鲁酱" class ="img-fluid" >
就只是比略缩图少了点东西,其他一样。自适应。
左右浮动 1 2 <img src ="img/miaonei.jpg" alt ="喵内噶" class ="img-thumbnail float-left" > <img src ="img/halu.jpg" alt ="哈鲁酱" class ="img-fluid float-right" >
不同屏幕 1 2 3 4 5 6 <picture > <source srcset ="img/abi.jpg" media ="(min-width: 1000px)" class ="img-fluid" > <source srcset ="img/halu.jpg" media ="(min-width: 800px)" class ="img-fluid" > <source srcset ="img/miaonei.jpg" media ="(min-width: 500px)" class ="img-fluid" > <img src ="img/nopower.jpg" alt ="这是当浏览器不支持picture标签时显示的图片" class ="img-fluid" > </picture >
h5标签,不同屏幕下显示不同的图片。
注意source的属性是srcset,Bootstrap中文站的代码少了个set。
常用组件 警告提示框(Alert) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 <div class ="alert alert-primary" role ="alert" > This is a primary alert with <a href ="#" class ="alert-link" > an example link</a > . Give it a click if you like. </div > <div class ="alert alert-secondary" role ="alert" > This is a secondary alert with <a href ="#" class ="alert-link" > an example link</a > . Give it a click if you like. </div > <div class ="alert alert-success" role ="alert" > This is a success alert with <a href ="#" class ="alert-link" > an example link</a > . Give it a click if you like. </div > <div class ="alert alert-danger" role ="alert" > This is a danger alert with <a href ="#" class ="alert-link" > an example link</a > . Give it a click if you like. </div > <div class ="alert alert-warning" role ="alert" > This is a warning alert with <a href ="#" class ="alert-link" > an example link</a > . Give it a click if you like. </div > <div class ="alert alert-info" role ="alert" > This is a info alert with <a href ="#" class ="alert-link" > an example link</a > . Give it a click if you like. </div > <div class ="alert alert-light" role ="alert" > This is a light alert with <a href ="#" class ="alert-link" > an example link</a > . Give it a click if you like. </div > <div class ="alert alert-dark" role ="alert" > This is a dark alert with <a href ="#" class ="alert-link" > an example link</a > . Give it a click if you like. </div >
alert:代表这是个警告提示框,里面规定了位置、边框等东西
alert-xxxx:进一步的规定了带alert的div的颜色、背景、字体样式
role=“alert”:H5语义化标签,告诉搜索引擎这个div的作用是alert提示框,用途是帮助残疾人,尤其是需要依靠屏幕阅读器和不能使用鼠标的用户
alert-link:alert提示框里面的超链接,对alert进行了颜色和字体的适配
面包屑导航 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <nav aria-label ="breadcrumb" > <ol class ="breadcrumb" > <li class ="breadcrumb-item active" aria-current ="page" > Home</li > </ol > </nav > <nav aria-label ="breadcrumb" > <ol class ="breadcrumb" > <li class ="breadcrumb-item" > <a href ="#" > Home</a > </li > <li class ="breadcrumb-item active" aria-current ="page" > Library</li > </ol > </nav > <nav aria-label ="breadcrumb" > <ol class ="breadcrumb" > <li class ="breadcrumb-item" > <a href ="#" > Home</a > </li > <li class ="breadcrumb-item" > <a href ="#" > Library</a > </li > <li class ="breadcrumb-item active" aria-current ="page" > Data</li > </ol > </nav >
这个面包屑导航就是类似于那种小说阅读目录,或者更适应的例子是文件夹的路径那种。
按钮 按钮样式 1 2 3 4 5 6 7 8 9 10 <button type ="button" class ="btn btn-primary" > Primary</button > <button type ="button" class ="btn btn-secondary" > Secondary</button > <button type ="button" class ="btn btn-success" > Success</button > <button type ="button" class ="btn btn-danger" > Danger</button > <button type ="button" class ="btn btn-warning" > Warning</button > <button type ="button" class ="btn btn-info" > Info</button > <button type ="button" class ="btn btn-light" > Light</button > <button type ="button" class ="btn btn-dark" > Dark</button > <button type ="button" class ="btn btn-link" > Link</button >
按钮的多种样式
btn:按钮的基本样式,去除原生html里的各种效果
btn-xxx:重置按钮的颜色、样式
type=“button”:这里因为本来就是button标签所以说不加也行,主要是为了下面的
按钮标签(多种按钮) 1 2 3 4 5 6 <a class ="btn btn-primary" href ="#" role ="button" > Link</a > <button class ="btn btn-primary" type ="submit" > Button</button > <input class ="btn btn-primary" type ="button" value ="Input" > <input class ="btn btn-primary" type ="submit" value ="Submit" > <input class ="btn btn-primary" type ="reset" value ="Reset" >
这里表明按钮可以有多种标签,不只是。 常见的三种主要就是a、input、button。 最好加上语义化标签,就是type=“button”或者其他的什么。
镂空按钮 1 2 3 4 5 6 7 8 9 <button type ="button" class ="btn btn-outline-primary" > Primary</button > <button type ="button" class ="btn btn-outline-secondary" > Secondary</button > <button type ="button" class ="btn btn-outline-success" > Success</button > <button type ="button" class ="btn btn-outline-danger" > Danger</button > <button type ="button" class ="btn btn-outline-warning" > Warning</button > <button type ="button" class ="btn btn-outline-info" > Info</button > <button type ="button" class ="btn btn-outline-light" > Light</button > <button type ="button" class ="btn btn-outline-dark" > Dark</button >
镂空样式的按钮
btn-outline-xxx:镂空样式的按钮,同时也有多种等级。
其余按钮
1 2 3 4 5 6 7 <button type ="button" class ="btn btn-primary btn-lg" > Large button</button > <button type ="button" class ="btn btn-secondary btn-sm" > Small button</button > <button type ="button" class ="btn btn-secondary " aria-pressed ="true" > Active-Pressed button</button > <button type ="button" class ="btn btn-secondary " disabled > Disabled button</button > <a type ="button" class ="btn btn-secondary disabled" aria-disabled ="true" > Disabled-A button</a >
按钮组1 2 3 4 5 6 7 8 9 10 11 12 13 14 <div class ="btn-group" role ="group" aria-label ="Button group with nested dropdown" > <button type ="button" class ="btn btn-secondary" > 1</button > <button type ="button" class ="btn btn-secondary" > 2</button > <div class ="btn-group" role ="group" > <button id ="btnGroupDrop1" type ="button" class ="btn btn-secondary dropdown-toggle" data-toggle ="dropdown" aria-haspopup ="true" aria-expanded ="false" > Dropdown </button > <div class ="dropdown-menu" aria-labelledby ="btnGroupDrop1" > <a class ="dropdown-item" href ="#" > Dropdown link</a > <a class ="dropdown-item" href ="#" > Dropdown link</a > </div > </div > </div >
按钮组就是一组按钮,用btn-group将btn包括起来。
当然这里的第三个按钮比较特殊,是个下拉式的按钮。这里用的data-toggle=“dropdown”
这个属性,好像是触发js里的什么东西。
aria的意思是Accessible Rich Internet Application,aria-*的作用就是描述这个tag在可视化的情境中的具体信息。比如:
1 <div role ="checkbox" aria-checked ="checked" > </div >
辅助工具就会知道,这个div实际上是个checkbox的角色,为选中状态。
卡片Card 1 2 3 4 5 6 7 8 9 <div class ="card" style ="width: 30rem;" > <img class ="card-img-top" src ="img/miaonei.jpg" alt ="Card image cap" > <div class ="card-body" > <h5 class ="card-title" > 你针棒!</h5 > <h6 class ="card-subtitle mt-2 mb-2 text-muted" > 那你真的很棒棒</h6 > <p class ="card-text" > 我贴鱼Bill,你们看我这手6不6,口住!藏经阁雅座一位!</p > <a href ="#" class ="btn btn-primary" > 前往藏经阁</a > </div > </div >
首先大的div用card包括起来,然后它的宽度是自定义的。没有自定义的话默认100%。
在card的div里面,可以使用各种card的元素。 比如这里使用的:
card-img-top:位于card顶部的一个图片
card-body:card的主体,里面包括一些东西
card-title:card-body中文本的标题
card-subtitle:card-body中的副标题;不过这里的显示效果是后面几个类控制的
mt-2:margin-top-2
mb-2:margin-bottom-2
text-muted:灰色字体
card-link:card中的超链接。
card里面的内容可以自定义,比如图片和文字可以左右布局,可以指定order排序,可以使用card-img-bottom(但是这里使用时不知道为什么不管用)等等来对card内部进行布局。是非常常用的一个组件。
轮播图(Carousel) carousel:旋转木马,轮盘传送带,机场的旋转行李传送带
轮播图例子(注释) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 <div id ="c1" class ="carousel slide m-auto w-50" data-ride ="carousel" > <div class ="carousel-inner" > <div class ="carousel-item active" > <img src ="img/carousel/GIF.gif" class ="d-block w-100" alt ="..." > <div class ="carousel-caption d-none d-md-block" > <h5 > EX咖喱棒!</h5 > <p > 吾王剑之所指,吾等心之所向!</p > <button class ="btn btn-sm btn-danger" > 奥利给!</button > </div > </div > <div class ="carousel-item" > <img src ="img/carousel/cimg2.jpg" class ="d-block w-100" alt ="..." > <div class ="carousel-caption d-none d-md-block" > <h5 > 真香定律</h5 > <p > 我棉被王就是饿死,死外面,从这跳下去,也不会吃你们卫宫家一口饭!</p > </div > </div > <div class ="carousel-item" > <img src ="img/carousel/cimg3.jpg" class ="d-block w-100" alt ="..." > <div class ="carousel-caption d-none d-md-block" > <h5 > 艾蕾酱真可爱</h5 > <p > 谁说冥界没有花朵,冥界只有一朵盛开的红色的花。</p > </div > </div > </div > <a class ="carousel-control-prev" href ="#c1" role ="button" data-slide ="prev" > <span class ="carousel-control-prev-icon" aria-hidden ="true" > </span > </a > <a class ="carousel-control-next" href ="#c1" role ="button" data-slide ="next" > <span class ="carousel-control-next-icon" aria-hidden ="true" > </span > </a > <ol class ="carousel-indicators" > <li data-target ="#c1" data-slide-to ="0" class ="active" > </li > <li data-target ="#c1" data-slide-to ="1" > </li > <li data-target ="#c1" data-slide-to ="2" > </li > </ol > </div >
都在代码里面了。
这里需要注意的就是那个绑定id。还有就是相关的层次内容,不能用错层次了各种div。
轮播图例子2(淡入淡出) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 <div id ="c2" class ="carousel slide m-auto w-50 carousel-fade" data-ride ="carousel" > <div class ="carousel-inner" > <div class ="carousel-item active" > <img src ="img/carousel/GIF.gif" class ="d-block w-100" alt ="..." > <div class ="carousel-caption d-none d-md-block" > <h5 > EX咖喱棒!</h5 > <p > 吾王剑之所指,吾等心之所向!</p > <button class ="btn btn-sm btn-danger" > 奥利给!</button > </div > </div > <div class ="carousel-item" > <img src ="img/carousel/cimg2.jpg" class ="d-block w-100" alt ="..." > <div class ="carousel-caption d-none d-md-block" > <h5 > 真香定律</h5 > <p > 我棉被王就是饿死,死外面,从这跳下去,也不会吃你们卫宫家一口饭!</p > </div > </div > <div class ="carousel-item" > <img src ="img/carousel/cimg3.jpg" class ="d-block w-100" alt ="..." > <div class ="carousel-caption d-none d-md-block" > <h5 > 艾蕾酱真可爱</h5 > <p > 谁说冥界没有花朵,冥界只有一朵盛开的红色的花。</p > </div > </div > </div > <a class ="carousel-control-prev" href ="#c2" role ="button" data-slide ="prev" > <span class ="carousel-control-prev-icon" aria-hidden ="true" > </span > </a > <a class ="carousel-control-next" href ="#c2" role ="button" data-slide ="next" > <span class ="carousel-control-next-icon" aria-hidden ="true" > </span > </a > <ol class ="carousel-indicators" > <li data-target ="#c2" data-slide-to ="0" class ="active" > </li > <li data-target ="#c2" data-slide-to ="1" > </li > <li data-target ="#c2" data-slide-to ="2" > </li > </ol > </div >
比如这里,加了个淡入淡出的切换效果,就是最外层的carousel-fade属性。
还可调整轮播每个图片的时间,可以在carousel-item上加个属性,如 <div class="carousel-item active" data-interval="10000">
,加了data-interval的属性。就是这个图片显示多少时间,然后切换到下一个。1000应该就是1s。
使用js调整效果 1 2 3 4 5 6 <script > $(".carousel" ).carousel({ interval: 500 } ) </script >
通过JavaScript 通过下面方法使用JS控制轮播(实现自动滚动):
1 $('.carousel' ).carousel()
选项 可以通过data-
方法,定义此轮播组件的属性,方法是data-interval=""
,实现JavaScript属性的注入,订制此组件的各种形态。
名称
Type类型
默认值
描述
interval
number
5000
自动循环项目之间的延迟时间(即滚动时间),如果为false,则整个轮播组件不会自动滚动(仅支持手动滚动)-在调试CSS样式时这很实用。
keyboard
boolean
true
是否应对键盘事件作出反应,如果选择true则可以通过键盘上的左<-右->方向键进行切换控制。
pause
string | boolean
“hover”
如果设置为"hover"
, 则鼠标移在动画屏幕上暂停旋转,并在移开鼠标后恢复旋转事件(这是默认属性);如设置为false
,则鼠标移上去轮播动画不会暂停。 在触摸屏幕上,当设置为"hover"
属性时,循环将在触控时暂停(一旦用户完成与旋转事件的交互)两个时间间隔自动恢复。 请注意,这是上述鼠标行为的补充。
ride
string
false
在用户手动循环第一个项目后自动播放传送带, 如果“carousel”则加载时自动播放传送带。
wrap
boolean
true
转盘是否应该连续循环或难以停止。
模态框 模态框就是个Bootstrap里面自带的弹框,当然底层是用html+css+js实现的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 <button type ="button" class ="btn btn-primary" data-toggle ="modal" data-target ="#exampleModal" > 弹窗 </button > <div class ="modal fade" id ="exampleModal" tabindex ="-1" role ="dialog" aria-labelledby ="exampleModalLabel" aria-hidden ="true" > <div class ="modal-dialog" role ="document" > <div class ="modal-content" > <div class ="modal-header" > <h5 class ="modal-title" id ="exampleModalLabel" > 弹窗的标题</h5 > <button type ="button" class ="close" data-dismiss ="modal" aria-label ="Close" > <span aria-hidden ="true" > × </span > </button > </div > <div class ="modal-body" > 弹窗的内容 </div > <div class ="modal-footer" > <button type ="button" class ="btn btn-secondary" data-dismiss ="modal" > 关闭按钮</button > <button type ="button" class ="btn btn-primary" > 另一个按钮</button > </div > </div > </div > </div >
这里在button
中的data-toggle=“modal”
和data-target=”#id“
是必不可少的,并且绑定到下面的弹框的div的id上。然后role="dialog" aria-labelledby="exampleModalLabel aria-hidden="true""
就是语义化的标签了,可以省略。
data-toggle=“modal”:表明这个按钮的弹出内容是个模态框
data-target=“id”:绑定到id元素上
同样这样里也遵循content>header-body-footer这样的一个顺序,和card差不多。还有很多相似的。
导航栏 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 <div class ="container" > <nav class ="navbar navbar-expand-lg navbar-light bg-warning" > <a class ="navbar-brand" href ="#" > 迦勒底</a > <button class ="navbar-toggler" type ="button" data-toggle ="collapse" data-target ="#navbarSupportedContent" aria-controls ="navbarSupportedContent" aria-expanded ="false" aria-label ="Toggle navigation" > <span class ="navbar-toggler-icon" > </span > </button > <div class ="collapse navbar-collapse" id ="navbarSupportedContent" > <ul class ="navbar-nav mr-auto" > <li class ="nav-item active" > <a class ="nav-link" href ="#" > 主页 <span class ="sr-only" > (current)</span > </a > </li > <li class ="nav-item" > <a class ="nav-link" href ="#" > 简介</a > </li > <li class ="nav-item dropdown" > <a class ="nav-link dropdown-toggle" href ="#" id ="navbarDropdown" role ="button" data-toggle ="dropdown" aria-haspopup ="true" aria-expanded ="false" > 转移 </a > <div class ="dropdown-menu" aria-labelledby ="navbarDropdown" > <a class ="dropdown-item" href ="#" > 冬木</a > <a class ="dropdown-item" href ="#" > 巴黎</a > <div class ="dropdown-divider" > </div > <a class ="dropdown-item" href ="#" > 月之海</a > </div > </li > <li class ="nav-item" > <a class ="nav-link disabled" href ="#" > 禁用</a > </li > </ul > <form class ="form-inline my-2 my-lg-0" > <input class ="form-control mr-sm-2" type ="search" placeholder ="查找" aria-label ="Search" > <button class ="btn btn-outline-success my-2 my-sm-0" type ="submit" > 搜索</button > </form > </div > </nav > </div >
都在注释里了。导航栏这里学会定制就可以,根据自己想要的样式改。
nav-expend-lg:在大屏幕之上展开,在大屏幕之下折叠起来。响应式。
toolTip就是指的这种提示方式:
实现的时候需要html+js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 <body style ="padding: 100px" > <button type ="button" class ="btn btn-secondary" data-toggle ="tooltip" data-placement ="top" title ="上面提示" > 这个按钮上面 </button > <button type ="button" class ="btn btn-secondary" data-toggle ="tooltip" data-placement ="right" title ="Tooltip on right" > Tooltip on right </button > <button type ="button" class ="btn btn-secondary" data-toggle ="tooltip" data-placement ="bottom" title ="Tooltip on bottom" > Tooltip on bottom </button > <button type ="button" class ="btn btn-secondary" data-toggle ="tooltip" data-placement ="left" title ="Tooltip on left" > Tooltip on left </button > <script src ="lib/js/jquery-3.4.1.js" > </script > <script src ="lib/js/popper.js" > </script > <script src ="lib/js/bootstrap.js" > </script > <script > $('.btn' ).tooltip() </script > </body >