亚洲区国产区激情区无码区,国产成人mv视频在线观看,国产A毛片AAAAAA,亚洲精品国产首次亮相在线

Bootstrap4 網(wǎng)格系統(tǒng)

Bootstrap網(wǎng)格系統(tǒng)是創(chuàng)建響應式網(wǎng)頁布局的最快,最簡單的方法。

Bootstrap 提供了一套響應式、移動設備優(yōu)先的流式網(wǎng)格系統(tǒng),隨著屏幕或視口(viewport)尺寸的增加,系統(tǒng)會自動分為最多 12 列。

我們也可以根據(jù)自己的需要,定義列數(shù):

111111111111
444
48
66
12

Bootstrap 4 的網(wǎng)格系統(tǒng)是響應式的,列會根據(jù)屏幕大小自動重新排列。

網(wǎng)格類

Bootstrap 4包含預定義的網(wǎng)格類,可為不同類型的設備(例如手機,平板電腦,筆記本電腦和臺式機等)快速制作網(wǎng)格布局。例如,您可以使用這些.col-*類為縱向模式下的超小型設備創(chuàng)建網(wǎng)格列,同樣,您可以使用這些.col-sm-*類為小屏幕設備(如橫向模式下的移動電話),.col-md-*中型屏幕設備(如平板電腦),.col-lg-*大型設備(如臺式機)和.col-xl-*超大臺式機屏幕的類創(chuàng)建網(wǎng)格列。

Bootstrap 4 網(wǎng)格系統(tǒng)有以下 5 個類:

  • .col- 針對所有設備

  • .col-sm- 平板  - 屏幕寬度等于或大于 576px

  • .col-md- 桌面顯示器  - 屏幕寬度等于或大于 768px)

  • .col-lg- 大桌面顯示器  - 屏幕寬度等于或大于 992px)

  • .col-xl- 超大桌面顯示器 - 屏幕寬度等于或大于 1200px)

網(wǎng)格系統(tǒng)規(guī)則

Bootstrap4 網(wǎng)格系統(tǒng)規(guī)則:

  • 網(wǎng)格每一行需要放在設置了 .container (固定寬度) 或 .container-fluid (全屏寬度) 類的容器中,這樣就可以自動設置一些外邊距與內(nèi)邊距。

  • 使用行來創(chuàng)建水平的列組。

  • 內(nèi)容需要放置在列中,并且只有列可以是行的直接子節(jié)點。

  • 預定義的類如 .row 和 .col-sm-4 可用于快速制作網(wǎng)格布局。

  • 列通過填充創(chuàng)建列內(nèi)容之間的間隙。 這個間隙是通過 .rows 類上的負邊距設置第一行和最后一列的偏移。

  • 網(wǎng)格列是通過跨越指定的 12 個列來創(chuàng)建。 例如,設置三個相等的列,需要使用用三個.col-sm-4 來設置。

  • Bootstrap 3 和 Bootstrap 4 最大的區(qū)別在于 Bootstrap 4 現(xiàn)在使用 flexbox(彈性盒子) 而不是浮動。   Flexbox 的一大優(yōu)勢是,沒有指定寬度的網(wǎng)格列將自動設置為等寬與等高列 。 如果您想了解有關(guān)Flexbox的更多信息,可以閱讀我們的CSS Flexbox教程。

下表總結(jié)了 Bootstrap 網(wǎng)格系統(tǒng)如何在不同設備上工作的:


超小設備
<576px
平板
≥576px
桌面顯示器
≥768px
大桌面顯示器
≥992px
超大桌面顯示器
≥1200px
容器最大寬度None (auto)540px720px960px1140px
類前綴.col-.col-sm-.col-md-.col-lg-.col-xl-
列數(shù)量和12
間隙寬度30px (一個列的每邊分別 15px)
可嵌套Yes
列排序Yes

以下各個類可以一起使用,從而創(chuàng)建更靈活的頁面布局。

Bootstrap 4 網(wǎng)格的基本結(jié)構(gòu)

以下代碼為 Bootstrap 4 網(wǎng)格的基本結(jié)構(gòu):

Bootstrap4  網(wǎng)格基本結(jié)構(gòu)

<!-- 第一個實例:控制列的寬度及在不同的設備上如何顯示 -->
<div class="row">
  <div class="col-*-*"></div>
</div>
<div class="row">
  <div class="col-*-*"></div>
  <div class="col-*-*"></div>
  <div class="col-*-*"></div>
</div>
 
<!-- 第二個實例:或讓 Bootstrap 者自動處理布局 -->
<div class="row">
  <div class="col"></div>
  <div class="col"></div>
  <div class="col"></div>
</div>

第一個實例:創(chuàng)建一行(<div class="row">)。然后, 添加是需要的列(.col-*-* 類中設置)。 第一個星號 (*) 表示響應的設備: sm, md, lg 或 xl, 第二個星號 (*) 表示一個數(shù)字, 同一行的數(shù)字相加為 12。

第二個實例: 不在每個 col 上添加數(shù)字,讓 bootstrap 自動處理布局,同一行的每個列寬度相等: 兩個 "col" ,每個就為 50% 的寬度。三個  "col"每個就為 33.33% 的寬度,四個  "col"每個就為 25% 的寬度,以此類推。同樣,你可以使用 .col-sm|md|lg|xl 來設置列的響應規(guī)則。

接下來我們可以看看示例。

創(chuàng)建相等寬度的列,Bootstrap 自動布局

<!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>Hello World!</h1>
  <p>創(chuàng)建三個相等寬度的列! 嘗試在 class="row" 的 div 中添加新的 class="col"  div,會顯示四個等寬的列。</p>
  <div class="row">
    <div class="col" style="background-color:lavender;">.col</div>
    <div class="col" style="background-color:orange;">.col</div>
    <div class="col" style="background-color:lavender;">.col</div>
  </div>
</div>
</body>
</html>
測試看看 ?/?

等寬響應式列

以下示例演示了如何在平板及更大屏幕上創(chuàng)建等寬度的響應式列。 在移動設備上,即屏幕寬度小于 576px 時,四個列將會上下堆疊排版:

<!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>Hello World!</h1>
  <p>重置瀏覽器大小查效果。</p>
  <p> 在移動設備上,即屏幕寬度小于 576px 時,四個列將會上下堆疊排版。</p>
  <div class="row">
    <div class="col-sm-3" style="background-color:lavender;">.col-sm-3</div>
    <div class="col-sm-3" style="background-color:lavenderblush;">.col-sm-3</div>
    <div class="col-sm-3" style="background-color:lavender;">.col-sm-3</div>
    <div class="col-sm-3" style="background-color:lavenderblush;">.col-sm-3</div>
  </div>
</div>
</body>
</html>
測試看看 ?/?

不等寬響應式列

以下示例演示了在平板及更大屏幕上創(chuàng)建不等寬度的響應式列。 在移動設備上,即屏幕寬度小于 576px 時,兩個列將會上下堆疊排版:

<!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>Hello World!</h1>
  <p>重置瀏覽器大小查效果。</p>
  <p>在移動設備上,即屏幕寬度小于 576px 時,四個列將會上下堆疊排版。</p>
  <div class="row">
    <div class="col-sm-4" style="background-color:lavender;">.col-sm-4</div>
    <div class="col-sm-8" style="background-color:lavenderblush;">.col-sm-8</div>
  </div>
</div>
</body>
</html>
測試看看 ?/?

平板和桌面端

以下示例演示了在桌面設備的顯示器上兩個列的寬度各占 50%,如果在平板端則左邊的寬度為 25%,右邊的寬度為 75%, 在移動手機等小型設備上會堆疊顯示。

<!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>平板與桌面的網(wǎng)格布局</h1>
  <p>以下示例演示了在桌面設備的顯示器上兩個列的寬度各占 50%,如果在平板端則左邊的寬度為 25%,右邊的寬度為 75%, 在移動手機等小型設備上會堆疊顯示。
</p>
  <p>重置瀏覽器窗口大小,查看效果。</p>
  <div class="container-fluid">
    <div class="row">
      <div class="col-sm-3 col-md-6 bg-success">
        nhooo
      </div>
      <div class="col-sm-9 col-md-6 bg-warning">
        菜鳥教程
      </div>
    </div>
  </div>
</div>
</body>
</html>
測試看看 ?/?

平板、桌面、大桌面顯示器、超大桌面顯示器

以下示例在平板、桌面、大桌面顯示器、超大桌面顯示器的寬度比例為分別為:25%/75%、50%/50%、33.33%/66.67%、16.67/83.33%, 在移動手機等小型設備上會堆疊顯示。

<!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>平板、桌面、大桌面顯示器、超大桌面顯示器</h1>
  <p>以下示例在平板、桌面、大桌面顯示器、超大桌面顯示器的寬度比例為分別為:25%/75%、50%/50%、33.33%/66.67%、16.67/83.33%, 在移動手機等小型設備上會堆疊顯示。</p>
  <p>重置瀏覽器窗口大小,查看效果。</p>
  <div class="container-fluid">
    <div class="row">
      <div class="col-sm-3 col-md-6 col-lg-4 col-xl-2 bg-success">
        nhooo
      </div>
      <div class="col-sm-9 col-md-6 col-lg-8 col-xl-10 bg-warning">
        菜鳥教程
      </div>
    </div>
  </div>
</div>
</body>
</html>
測試看看 ?/?

偏移列

偏移列通過 offset-*-* 類來設置。第一個星號( * )可以是 sm、md、lg、xl,表示屏幕設備類型,第二個星號( * )可以是 111 的數(shù)字。

為了在大屏幕顯示器上使用偏移,請使用 .offset-md-* 類。這些類會把一個列的左外邊距(margin)增加 * 列,其中 * 范圍是從 111。

例如:.offset-md-4 是把.col-md-4 往右移了四列格。

<!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>偏移列</h1>
  <p>.offset-md-4 是把.col-md-4 往右移了四列格。</p>
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-4 bg-success">.col-md-4</div>
      <div class="col-md-4 offset-md-4 bg-warning">.col-md-4 .offset-md-4</div>
    </div>
    <div class="row">
      <div class="col-md-3 offset-md-3 bg-success">.col-md-3 .offset-md-3</div>
      <div class="col-md-3 offset-md-3 bg-warning">.col-md-3 .offset-md-3</div>
    </div>
    <div class="row">
      <div class="col-md-6 offset-md-3 bg-success">.col-md-6 .offset-md-3</div>
    </div>
  </div>
</div>
</body>
</html>
測試看看 ?/?

我們希望您已經(jīng)了解了新的Bootstrap 4網(wǎng)格系統(tǒng)的基礎知識。在接下來的幾章中,您將學習如何使用此flexbox網(wǎng)格系統(tǒng)創(chuàng)建基本的網(wǎng)頁布局。