Bootstrap包括多个预定义的按钮样式,每个样式都有自己的语义目的,另外还有一些额外的功能可以用于更多的控制。
样式效果:
源代码:
<body class="container">
<button type="button" class="btn btn-primary">Primarybutton>
<button type="button" class="btn btn-secondary">Secondarybutton>
<button type="button" class="btn btn-success">Successbutton>
<button type="button" class="btn btn-danger">Dangerbutton>
<button type="button" class="btn btn-warning">Warningbutton>
<button type="button" class="btn btn-info">Infobutton>
<button type="button" class="btn btn-light">Lightbutton>
<button type="button" class="btn btn-dark">Darkbutton>
<button type="button" class="btn btn-link">Linkbutton>
body>
.btn 在引用中,实现轮廓按钮可以用默认修饰符类替换.btn-outline-*任何按钮上的所有背景颜色和图像。
样式效果:
源代码:
<body class="container">
<button type="button" class="btn btn-outline-primary">Primarybutton>
<button type="button" class="btn btn-outline-secondary">Secondarybutton>
<button type="button" class="btn btn-outline-success">Successbutton>
<button type="button" class="btn btn-outline-danger">Dangerbutton>
<button type="button" class="btn btn-outline-warning">Warningbutton>
<button type="button" class="btn btn-outline-info">Infobutton>
<button type="button" class="btn btn-outline-light">Lightbutton>
<button type="button" class="btn btn-outline-dark">Darkbutton>
body>
使用按钮组合,可以把一系列按钮编组在一行里,将一系列的 .btn 包裹在.btn-group内。
样式效果:
源代码:
<body class="container">
<div class="btn-group" role="group" aria-label="Basic example">
<button type="button" class="btn btn-secondary">Leftbutton>
<button type="button" class="btn btn-secondary">Middlebutton>
<button type="button" class="btn btn-secondary">Rightbutton>
div>
body>
添加.btn-group-vertical 将一组按钮垂直排列 。
源代码:
<body class="container">
<div class="btn-group-vertical" role="group" aria-label="Basic example">
<button type="button" class="btn btn-secondary">Topbutton>
<button type="button" class="btn btn-secondary">Middlebutton>
<button type="button" class="btn btn-secondary">Bottombutton>
div>
body>
.card卡片组件是BootStrap 4新增的一组重要样式,它是一一个灵活的、可扩展的内容器,包含了可选的卡片头和卡片脚、一个大范围的内容、上下文背景色以及强大的显示选项。
Ps:如果 .card-title 和 .card-subtitle 组合放在 .card-body 中, 则可对齐主、副标题。
card-body源代码
<div class="card">
<div class="card-body"> This is some text within a card body. div>
div>
card-title与card-link源代码:
<body class="container">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">Card titleh5>
<h6 class="card-subtitle mb-2 text-muted">Card subtitleh6>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.p>
<a href="#" class="card-link">Card linka>
<a href="#" class="card-link">Another linka>
div>
div>
body>
源代码:
<body class="container">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="..." alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card titleh5>
<p class="card-text">
Some quick example text to build on the card title and make up
the bulk of the card's content.
p>
<a href="#" class="btn btn-primary">Go somewherea>
div>
div>
body>
源代码:
<body class="container">
<div class="card" style="width: 18rem;">
<ul class="list-group list-group-flush">
<li class="list-group-item">Cras justo odioli>
<li class="list-group-item">Dapibus ac facilisis inli>
<li class="list-group-item">Vestibulum at erosli>
ul>
div>
body>
源代码:
<body class="container">
<div class="card">
<div class="card-header"> Featured div>
<div class="card-body">
<h5 class="card-title">Special title treatmenth5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.p>
div>
<div class="card-footer">
<a href="#" class="btn btn-primary">Go somewherea>
div>
div>
body>
文本控件(如
、、
)统一采用 .form-control 样式进行处理优化,包括常规外观、focus选(点)中状态、尺寸大小等。
垂直布局源代码:
<body class="container">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="defaultCheck1">
<label class="form-check-label" for="defaultCheck1">
Option one is this and that—be sure to include why it's great
label>
div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="defaultCheck2">
<label class="form-check-label" for="defaultCheck2">
Option one is this and that—be sure to include why it's great
label>
div>
body>
水平布局源代码:
<body class="container">
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="inlineCheckbox1" value="option1">
<label class="form-check-label" for="inlineCheckbox1">拿铁label>
div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="inlineCheckbox2" value="option2">
<label class="form-check-label" for="inlineCheckbox2">摩卡label>
div>
body>
.form-group 群组可以向为表单赋予一些结构样式,其唯一目的是提供标签的控制配对以及margin-bottom 属性,可以在 源代码: 使用 .form-inline样式在单个水平行上显示一系列标签,表单控件和按钮。 源代码: 可以使用…form-text t创建表单中的块级帮助文本。 源代码: 源代码: 添加 .active 到 .list-group-item 下的其中一行或多行,以指示当前有效的选择状态。 源代码: 加入.list-group-flush选择器,可以实现移除部分边框以及圆角,从而产生边缘贴齐的列表组 源代码: Bootstrap中提供的导航可共享通用标记和样式,从基础.nav样式类到活动与禁用状态 水平排列源代码: 垂直排列源代码: 源代码: 源代码: 使用.nav-fill会将 .nav-item按照比例分配空间 源代码: .navbar-brand:为您的公司,产品或项目名称。 源代码: 源代码: 固定在顶部的源代码: 固定在底部的源代码:、
<body class="container">
<div class="form-group">
<label for="formGroupExampleInput">Example labellabel>
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input">
div>
<div class="form-group">
<label for="formGroupExampleInput2">Another labellabel>
<input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input">
div>
body>
3.3、内联式表单
<form class="form-inline">
<label class="sr-only" for="inlineFormInputName2">Namelabel>
<input type="text" class="form-control mb-2 mr-sm-2" id="inlineFormInputName2" placeholder="Jane Doe">
<label class="sr-only" for="inlineFormInputGroupUsername2">Usernamelabel>
……
form>
3.4、表单下方帮助提示文本
<body class="container">
<label for="inputPassword5">Passwordlabel>
<input type="password" id="inputPassword5" class="form-control" aria-escribedby="passwordHelpBlock">
<small id="passwordHelpBlock" class="form-text text-muted">
Your password must be 8-20 characters long, contain letters and numbers, and must not contain spaces, special characters, or emoji.
small>
body>
<body class="container">
<form class="form-inline">
<div class="form-group">
<label for="inputPassword6">Passwordlabel>
<input type="password" id="inputPassword6" class="form-control mx-sm-3" aria-
describedby="passwordHelpInline">
<small id="passwordHelpInline" class="text-muted"> Must be 8-20 characters long.
small>
div>
form>
body>
四、列表与导航
4.1、状态指示列表组
<body class="container">
<ul class="list-group">
<li class="list-group-item active">Cras justo odioli>
<li class="list-group-item">Dapibus ac facilisis inli>
<li class="list-group-item">Morbi leo risusli>
<li class="list-group-item">Porta ac consectetur acli>
<li class="list-group-item">Vestibulum at erosli>
ul>
body>
4.2、无边框的列表
<body class="container">
<ul class="list-group list-group-flush">
<li class="list-group-item ">Cras justo odioli>
<li class="list-group-item">Dapibus ac facilisis inli>
<li class="list-group-item">Morbi leo risusli>
<li class="list-group-item">Porta ac consectetur acli>
<li class="list-group-item">Vestibulum at erosli>
ul>
body>
4.3、通用导航
<body class="container">
<ul class="nav justify-content-center">
<li class="nav-item">
<a class="nav-link active" href="#">Activea>
li>
<li class="nav-item">
<a class="nav-link" href="#">Linka>
li>
<li class="nav-item">
<a class="nav-link" href="#">Linka>
li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disableda>
li>
ul>
body>
<body class="container">
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" href="#">Activea>
li>
<li class="nav-item">
<a class="nav-link" href="#">Linka>
li>
<li class="nav-item">
<a class="nav-link" href="#">Linka>
li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disableda>
li>
ul>
body>
4.4、选项卡样式导航
<body class="container">
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" href="#">Activea>
li>
<li class="nav-item">
<a class="nav-link" href="#">Linka>
li>
<li class="nav-item">
<a class="nav-link" href="#">Linka>
li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disableda>
li>
ul>
body>
4.5、胶囊样式导航
<body class="container">
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" href="#">Activea>
li>
<li class="nav-item">
<a class="nav-link" href="#">Linka>
li>
<li class="nav-item">
<a class="nav-link" href="#">Linka>
li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disableda>
li>
ul>
body>
4.6、等比导航
<body class="container">
<ul class="nav nav-pills nav-fill">
<li class="nav-item">
<a class="nav-link active" href="#">Activea>
li>
<li class="nav-item">
<a class="nav-link" href="#">Linka>
li>
<li class="nav-item">
<a class="nav-link" href="#">Linka>
li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disableda>
li>
ul>
body>
4.7、带标题的导航
.justify-content-end :设置导航在右侧<body class="container">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class=“container”>
<a class="navbar-brand" href="#">BEN的博客a>
<div>
<ul class="navbar-nav" >
<li class="nav-item" ><a class="nav-link" href="#"> 主页 a>li>
<li class="nav-item" ><a class="nav-link" href="#"> 技术 a>li>
<li class="nav-item" ><a class="nav-link" href="#"> 料理 a>li>
<li class="nav-item" ><a class="nav-link" href="#"> 摄影 a>li>
<li class="nav-item" ><a class="nav-link" href="#"> 随笔 a>li>
ul>
div>
div>
nav>
body>
<body class="container">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="#">BEN的博客a>
<div class="justify-content-end">
<ul class="navbar-nav" >
<li class="nav-item" ><a class="nav-link" href="#"> 主页 a>li>
<li class="nav-item" ><a class="nav-link" href="#"> 技术 a>li>
<li class="nav-item" ><a class="nav-link" href="#"> 料理 a>li>
<li class="nav-item" ><a class="nav-link" href="#"> 摄影 a>li>
<li class="nav-item" ><a class="nav-link" href="#"> 随笔 a>li>
ul>
div>
div>
nav>
body>
4.8、定位导航栏
<body>
<nav class="navbar fixed-top navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="#">BEN的博客a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navList">
<span class="navbar-toggler-icon">span>
button>
<div class="justify-content-end collapse navbar-collapse" id="navList" >
<div class="justify-content-end collapse navbar-collapse">
<ul class="navbar-nav" >
<li class="nav-item" ><a class="nav-link" href="#"> 主页 a>li>
<li class="nav-item" ><a class="nav-link" href="#"> 技术 a>li>
<li class="nav-item" ><a class="nav-link" href="#"> 料理 a>li>
<li class="nav-item" ><a class="nav-link" href="#"> 摄影 a>li>
<li class="nav-item" ><a class="nav-link" href="#"> 随笔 a>li>
ul>
div>
div>
div>
nav>
body>
<body>
<nav class="navbar fixed-bottom navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="#">BEN的博客a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navList">
<span class="navbar-toggler-icon">span>
button>
<div class="justify-content-end collapse navbar-collapse" id="navList" >
<div class="justify-content-end collapse navbar-collapse">
<ul class="navbar-nav" >
<li class="nav-item" ><a class="nav-link" href="#"> 主页 a>li>
<li class="nav-item" ><a class="nav-link" href="#"> 技术 a>li>
<li class="nav-item" ><a class="nav-link" href="#"> 料理 a>li>
<li class="nav-item" ><a class="nav-link" href="#"> 摄影 a>li>
<li class="nav-item" ><a class="nav-link" href="#"> 随笔 a>li>
ul>
div>
div>
div>
nav>
body>