一、需要添加 HTML5 doctype
二、为了让 Bootstrap 开发的网站对移动设备友好,确保适当的绘制和触屏缩放,可以在head 之中添加 如下代码:
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
其中:
width=device-width 表示宽度是设备屏幕的宽度。
initial-scale=1 表示初始的缩放比例。
shrink-to-fit=no 自动适应手机屏幕的宽度。
三、需要一个容器元素来包裹网站的内容,可以使用以下两个容器类:
(1).container 类用于固定宽度并支持响应式布局的容器。
(2).container-fluid 类用于 100% 宽度,占据全部视口(viewport)的容器。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>测试</title>
<!-- 引入bootsrap -->
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1>我的第一个 Bootstrap 页面</h1>
<p>这是一些文本。</p>
</div>
<div class="container-fluid">
<h1>我的第一个 Bootstrap 页面</h1>
<p>使用了 .container-fluid,100% 宽度,占据全部视口(viewport)的容器。</p>
</div>
</body>
</html>
四、Bootstrap 提供了一套响应式、移动设备优先的流式网格系统,随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多 12 列(1/4/6/8/12列)。Bootstrap 4 的网格系统是响应式的,列会根据屏幕大小自动重新排列。Bootstrap 网格系统如何在不同设备上工作的:
超小设备 <576px | 平板 ≥576px | 桌面显示器 ≥768px | 大桌面显示器 ≥992px | 超大桌面显示器 ≥1200px | |
---|---|---|---|---|---|
容器最大宽度 | None (auto) | 540px | 720px | 960px | 1140px |
类前缀 | .col- | .col-sm- | .col-md- | .col-lg- | .col-xl- |
列数量和 | 12 | ||||
间隙宽度 | 30px (一个列的每边分别 15px) | ||||
可嵌套 | Yes | ||||
列排序 | Yes |