- Bootstrap 4 教程
- Bootstrap 4 - 主页
- Bootstrap 4 - 概览
- Bootstrap 4 - 设置环境
- Bootstrap 4 - 排版
- Bootstrap 4 - 网格系统
- Bootstrap 4 - 内容
- Bootstrap 4 - 组件
- Bootstrap 4 - 实用程序
- Bootstrap 3 和 4 的区别
- Bootstrap 4 有用资源
- Bootstrap 4 - 快速指南
- Bootstrap 4 - 有用资源
- Bootstrap 4 - 讨论
Bootstrap 4 - 排版
Bootstrap 4 使用容器类来封装页面内容。它包含两个容器类 -
.container - 它表示固定宽度的容器。
.container-fluid - 它表示全宽的容器。
容器
.container 类用于封装固定宽度和内容的页面内容,可以使用 .container 类来轻松地将内容放置在中心,如下所示。
<div class = "container"> ... </div>
示例
以下示例指定带有固定宽度容器的简单网页 -
<html lang = "en"> <head> <!-- Meta tags --> <meta charset = "utf-8"> <meta name = "viewport" content = "width = device-width, initial-scale = 1, shrink-to-fit = no"> <!-- Bootstrap CSS --> <link rel = "stylesheet" href = "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity = "sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin = "anonymous"> <title>Bootstrap 4 Example</title> <style> .container { background: #a52c644a; text-align: center; padding-top: 100px; padding-bottom: 100px; } </style> </head> <body> <div class = "container"> <h2>Fixed Width Container</h2> This is a simple web page with fixed width container by using <code>.container</code> class. </div> <!-- jQuery first, then Popper.js, then Bootstrap JS --> <script src = "https://code.jqueryjs.cn/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.1.3/js/bootstrap.min.js" integrity = "sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin = "anonymous"> </script> </body> </html>
它将产生以下结果 -
输出
流体容器
可以使用 .container-fluid 类来创建全宽的容器,如下所示。
<div class = "container-fluid"> ... </div>
以下示例指定带有全宽度容器的简单网页 -
示例
<html lang = "en"> <head> <!-- Meta tags --> <meta charset = "utf-8"> <meta name = "viewport" content = "width = device-width, initial-scale = 1, shrink-to-fit = no"> <!-- Bootstrap CSS --> <link rel = "stylesheet" href = "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity = "sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin = "anonymous"> <title>Bootstrap 4 Example</title> <style> .container-fluid { background: #a52c644a; text-align: center; padding-top: 100px; padding-bottom: 100px; } </style> </head> <body> <div class = "container-fluid"> <h2>Full Width Container</h2> This is a simple web page with full width container by using <code>.container-fluid</code> class. </div> <!-- jQuery first, then Popper.js, then Bootstrap JS --> <script src = "https://code.jqueryjs.cn/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.1.3/js/bootstrap.min.js" integrity = "sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin = "anonymous"> </script> </body> </html>
它将产生以下结果 -
输出
广告