English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Nous pouvons installer Bootstrap de deux manières4:
Utilisation de Bootstrap 4 CDN。
À partir du site officiel getbootstrap.com 下载 Bootstrap 4。
En Chine, il est recommandé d'utiliser les bibliothèques sur Staticfile CDN :
<!-- Nouveau Bootstrap4 Fichier CSS principal --> <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css"> <!-- Fichier jQuery. Assurez-vous de l'inclure avant bootstrap.min.js --> <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> <!-- bootstrap.bundle.min.js est utilisé pour les fenêtres contextuelles, les notifications et les menus déroulants, et inclut popper.min.js --> <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script> <!-- Le plus récent Bootstrap4 Fichier JavaScript principal --> <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
Attention :popper.min.js est utilisé pour configurer les fenêtres contextuelles, les notifications et les menus déroulants, bootstrap.bundle.min.js inclut déjà popper.min.js。
De plus, vous pouvez également utiliser les services CDN suivants :
国内推荐使用 : https://www.staticfile.org/
国际推荐使用:https://cdnjs.com/
你可以去官网 https://getbootstrap.com/ 下载 Bootstrap4 资源库。
注:此外你还可以通过包的管理工具 npm、 gem、 composer 等来安装:
npm install [email protected] gem 'bootstrap', '~> 4.0.0.beta2' composer require twbs/bootstrap:4.0.0-beta.2
Bootstrap 要求使用 HTML5 文件类型,所以需要添加 HTML5 doctype 声明。
HTML5 doctype 在文档头部声明,并设置对应编码:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> </html>
为了让 Bootstrap 开发的网站对移动设备友好,确保适当的绘制和触屏缩放,需要在网页的 head 之中添加 viewport meta 标签,如下所示:
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
width=device-width 表示宽度是设备屏幕的宽度。
initial-scale=1 表示初始的缩放比例。
shrink-to-fit=no 自动适应手机屏幕的宽度。
Bootstrap 4 需要一个容器元素来包裹网站的内容。
我们可以使用以下两个容器类:
.container 类用于固定宽度并支持响应式布局的容器。
.container-fluid 类用于 100% 宽度,占据全部视口(viewport)的容器。
<!DOCTYPE html> <html> <head> <title>Bootstrap 示例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/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.15.0/umd/popper.min.js"></script> <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <h1>Ma première page Bootstrap </h1> <p>这是一些文本。</p> </div> </body> </html>Voyons un test ‹/›
以下示例展示了占据全部视口(viewport)的容器。
<!DOCTYPE html> <html> <head> <title>Bootstrap 示例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/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.15.0/umd/popper.min.js"></script> <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> </head> <body> <div class="container-fluid"> <h1>Ma première page Bootstrap </h1> <p>Utilise <span class="container"></span>-fluid,100% largeur, conteneur prenant tout le viewport (viewport) </p> </div> </body> </html>Voyons un test ‹/›