Bootstrap


Bootstrap

  • Bootstrap是Twitter开源的基于HTML、CSS、JavaScript的前端框架。
  • 它是为实现快速开发Web应用程序而设计的一套前端工具包。
  • 它支持响应式布局,并且在V3版本之后坚持移动设备优先。
  • 官方地址:https://getbootstrap.com
  • 中文地址:http://www.bootcss.com/
  • 使用V3版本的Bootstrap,下载的是用于生产环境的Bootstrap。
  • 处理依赖:由于Bootstrap的某些组件依赖于jQuery,所以请确保下载对应版本的jQuery文件,来保证Bootstrap相关组件运行正常。
  • cdn : https://www.bootcdn.cn/

一、目录结构

bootstrap-3.3.7-dist/
├── css  // CSS文件
│   ├── bootstrap-theme.css  // Bootstrap主题样式文件
│   ├── bootstrap-theme.css.map
│   ├── bootstrap-theme.min.css  // 主题相关样式压缩文件
│   ├── bootstrap-theme.min.css.map
│   ├── bootstrap.css
│   ├── bootstrap.css.map
│   ├── bootstrap.min.css  // 核心CSS样式压缩文件
│   └── bootstrap.min.css.map
├── fonts  // 字体文件
│   ├── glyphicons-halflings-regular.eot
│   ├── glyphicons-halflings-regular.svg
│   ├── glyphicons-halflings-regular.ttf
│   ├── glyphicons-halflings-regular.woff
│   └── glyphicons-halflings-regular.woff2
└── js  // JS文件
    ├── bootstrap.js
    ├── bootstrap.min.js  // 核心JS压缩文件
    └── npm.js

1、Bootstrap引入

<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="dist/css/bootstrap.min.css" rel="stylesheet">
<script type="application/javascript" src="dist/jquery-3.1.1.js">script>
<script type="application/javascript" src="dist/js/bootstrap.min.js">

二、Bootstrap全局样式

  • 排版、按钮、表格、表单、图片等我们常用的HTML元素,Bootstrap中都提供了全局样式。
  • 只要在基本的HTML元素上通过设置class就能够应用上Bootstrap的样式,从而使页面更美观和谐。

1、标题相关

<h1>一级标题36pxh1>
<h2>二级标题30pxh2>
<h3>三级标题24pxh3>
<h4>四级标题18pxh4>
<h5>五级标题14pxh5>
<h6>六级标题12pxh6>


<span class="h1">一级标题36pxspan>
<span class="h2">二级标题30pxspan>
<span class="h3">三级标题24pxspan>
<span class="h4">四级标题18pxspan>
<span class="h5">五级标题14pxspan>
<span class="h6">六级标题12pxspan>


<h1>一级标题<small>小标题small>h1>

2、文本相关


<p class="text-left">文本左对齐p>
<p class="text-center">文本居中p>
<p class="text-right">文本右对齐p>


<p class="text-lowercase">Lowercased text.p>
<p class="text-uppercase">Uppercased text.p>
<p class="text-capitalize">Capitalized text.p>

3、表格相关

响应式表格:通过把任意的 .table 包在 .table-responsive class 内可以让表格水平滚动以适应小型设备(小于 768px)。当在大于 768px 宽的大型设备上查看时,看不到任何的差别。

<div class="container">

  <table class="table table-striped">
      
      <caption>条纹表格布局caption>
      <thead>
        <tr>
          <th>姓名th>
          <th>年龄th>
          <th>salaryth>
        tr>
      thead>
      <tbody>
        <tr>
          <td>Bobtd>
          <td>23td>
          <td>3000td>
        tr>
        <tr class="danger">
          <td>steventd>
          <td>34td>
          <td>5000td>
        tr>
        <tr class="success">
          <td>alvintd>
          <td>33td>
          <td>7000td>
        tr>

        <tr class="warning">
          <td>alvintd>
          <td>33td>
          <td>7000td>
        tr>
      tbody>
    table>
div>

4、状态相关

Class描述
.active 鼠标悬停在行或单元格上时所设置的颜色
.success 标识成功或积极的动作
.info 标识普通的提示信息或动作
.warning 标识警告或需要用户注意
.danger 标识危险或潜在的带来负面影响的动作

5、按钮相关

任何带有 class .btn 的元素都会继承圆角灰色按钮的默认外观。但是 Bootstrap 提供了一些选项来定义按钮的样式


<a class="btn btn-default" href="#" role="button">Linka>
<button class="btn btn-default" type="submit">Buttonbutton>
<input class="btn btn-default" type="button" value="Input">
<input class="btn btn-default" type="submit" value="Submit">


<button type="button" class="btn btn-default">(默认样式)Defaultbutton>

<button type="button" class="btn btn-primary">(首选项)Primarybutton>

<button type="button" class="btn btn-success">(成功)Successbutton>

<button type="button" class="btn btn-info">(一般信息)Infobutton>

<button type="button" class="btn btn-warning">(警告)Warningbutton>

<button type="button" class="btn btn-danger">(危险)Dangerbutton>

<button type="button" class="btn btn-link">(链接)Linkbutton>


<p>
  <button type="button" class="btn btn-primary btn-lg">(大按钮)Large buttonbutton>
  <button type="button" class="btn btn-default btn-lg">(大按钮)Large buttonbutton>
p>
<p>
  <button type="button" class="btn btn-primary">(默认尺寸)Default buttonbutton>
  <button type="button" class="btn btn-default">(默认尺寸)Default buttonbutton>
p>
<p>
  <button type="button" class="btn btn-primary btn-sm">(小按钮)Small buttonbutton>
  <button type="button" class="btn btn-default btn-sm">(小按钮)Small buttonbutton>
p>
<p>
  <button type="button" class="btn btn-primary btn-xs">(超小尺寸)Extra small buttonbutton>
  <button type="button" class="btn btn-default btn-xs">(超小尺寸)Extra small buttonbutton>
p>

6、图片相关

Bootstrap 提供了三个可对图片应用简单样式的 class:

  • .img-rounded:添加 border-radius:6px 来获得图片圆角。
  • .img-circle:添加 border-radius:50% 来让整个图片变成圆形。
  • .img-thumbnail:添加一些内边距(padding)和一个灰色的边框。

另外,通过在 标签添加 .img-responsive 类来让图片支持响应式设计。.img-responsive 类将 max-width: 100%; 和 height: auto; 样式应用在图片上


<img src="..." class="img-responsive" alt="Responsive image">


<img src="..." alt="..." class="img-rounded">
<img src="..." alt="..." class="img-circle">
<img src="..." alt="..." class="img-thumbnail">

7、表单相关

Bootstrap 提供了下列类型的表单布局:

  • 垂直表单(默认)
  • 内联表单
  • 水平表单

垂直表单

创建基本表单的步骤:

  • 向父
    元素添加 role="form"。
  • 把标签和控件放在一个带有 class .form-group 的
    中。这是获取最佳间距所必需的。
  • 向所有的文本元素