大 纲

前端的作用于采集输入信息,后端进行处理。计算机程序的界面样式,视觉呈现属于前端。本页主要记录我学习 Bootstrap 过程中觉得实用的笔记。

Bootstrap 是一套流行的前端框架,轻松构建对移动设备很友好的响应式网站。内置了大量常用界面设计组件,大大简化了建站的过程。

相关站点:框架官网 框架中文 菜鸟教程 框架仓库

加载框架

CSS 复制如下代码到HTML<head>标签。

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

JS 复制如下代码到HTML</body>标签之前。

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

简单 Bootstrap 实例

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
  <title>XXXX</title>
</head>
<body>
  <h1>XXXX</h1>
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>

容器

容器是Bootstrap中最基本的布局基础。会自动根据屏幕大小来选择合适的宽度。

<div class="container">
  XXXX
</div>
标签 名称 描述
container 容器 自动根据屏幕大小来选择合适的宽度
container-fluid 全宽容器 跨越 viewport 的整个宽度

响应式断点

响应式断点指使用少量媒体查询为布局和界面创建合理的断点,以此动态调节显示界面尺寸。

下述代码中具体尺寸更具需要进行更改。

@media (min-width: 576px) and (max-width: 767.98px) {  }
@media (min-width: 768px) and (max-width: 991.98px) {  }
@media (min-width: 992px) and (max-width: 1199.98px) {  }

层叠覆盖关系

Z-index值用于正确地分层,确然各个元素的层叠覆盖关系。

.XXXX {
  z-index: X;
}

参考资料

  1. 维基百科 https://zh.wikipedia.org/