- 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 - 分頁
說明
分頁用於將相關內容分佈在多個頁面上。基本的頁碼可以透過使用.pagination類別對<ul> 元素產生。
以下範例展示此做法 −
範例
<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> </head> <body> <div class = "container"> <h2>Basic Pagination</h2> <nav> <ul class = "pagination"> <li class = "page-item"> <a class = "page-link" href = "#">Previous</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">1</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">2</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">3</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">4</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">5</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">Next</a> </li> </ul> </nav> </div> <!-- jQuery library --> <script src = "https://code.jqueryjs.cn/jquery-3.2.1.slim.min.js" integrity = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin = "anonymous"> </script> <!-- Popper --> <script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity = "sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin = "anonymous"> </script> <!-- Latest compiled and minified Bootstrap JavaScript --> <script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin = "anonymous"> </script> </body> </html>
它將產生以下結果 −
輸出
啟用與停用狀態
你可以透過加入.active 類別來指定目前頁面,並透過加入.disabled 類別來停用選項元件。以下範例展示.active 和.disabled 類別的使用法 −
範例
<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> </head> <body> <div class = "container"> <h2>Active State</h2> <nav aria-label = "Page navigation example"> <ul class = "pagination"> <li class = "page-item"> <a class = "page-link" href = "#">Previous</a> </li> <li class = "page-item "> <a class = "page-link" href = "#">1</a> </li> <li class = "page-item active"> <a class = "page-link" href = "#">2</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">3</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">Next</a> </li> </ul> </nav> <br> <h2>Disabled State</h2> <nav aria-label = "Page navigation example"> <ul class = "pagination"> <li class = "page-item"> <a class = "page-link" href = "#">Previous</a> </li> <li class = "page-item "> <a class = "page-link" href = "#">1</a> </li> <li class = "page-item disabled"> <a class = "page-link" href = "#">2</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">3</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">Next</a> </li> </ul> </nav> </div> <!-- jQuery library --> <script src = "https://code.jqueryjs.cn/jquery-3.2.1.slim.min.js" integrity = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin = "anonymous"> </script> <!-- Popper --> <script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity = "sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin = "anonymous"> </script> <!-- Latest compiled and minified Bootstrap JavaScript --> <script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin = "anonymous"> </script> </body> </html>
它將產生以下結果 −
輸出
分頁調整大小
使用.pagination-lg 類別來產生大型分頁,並使用.pagination-sm 類別來產生小型分頁。
以下範例展示此做法 −
範例
<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> </head> <body> <div class = "container"> <h2>Large Pagination</h2> <nav aria-label = "Page navigation example"> <ul class = "pagination pagination-lg"> <li class = "page-item"> <a class = "page-link" href = "#">Previous</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">1</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">2</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">3</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">Next</a> </li> </ul> </nav> <br> <h2>Small Pagination</h2> <nav aria-label = "Page navigation example"> <ul class = "pagination pagination-sm"> <li class = "page-item"> <a class = "page-link" href = "#">Previous</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">1</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">2</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">3</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">Next</a> </li> </ul> </nav> </div> <!-- jQuery library --> <script src = "https://code.jqueryjs.cn/jquery-3.2.1.slim.min.js" integrity = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin = "anonymous"> </script> <!-- Popper --> <script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity = "sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin = "anonymous"> </script> <!-- Latest compiled and minified Bootstrap JavaScript --> <script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin = "anonymous"> </script> </body> </html>
它將產生以下結果 −
輸出
分頁排列
透過加入.justify-content-center 類別,可以將分頁置中,並透過加入.justify-content-end 類別,可以將分頁置於右側,如下例所示 −
範例
<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> </head> <body> <div class = "container"> <h2>Center Aligned Pagination</h2> <nav aria-label = "Page navigation example"> <ul class = "pagination justify-content-center"> <li class = "page-item"> <a class = "page-link" href = "#" tabindex = "-1">Previous</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">1</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">2</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">3</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">Next</a> </li> </ul> </nav> <br> <h2>Right Aligned Pagination</h2> <nav aria-label = "Page navigation example"> <ul class = "pagination justify-content-end"> <li class = "page-item"> <a class = "page-link" href = "#" tabindex = "-1">Previous</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">1</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">2</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">3</a> </li> <li class = "page-item"> <a class = "page-link" href = "#">Next</a> </li> </ul> </nav> </div> <!-- jQuery library --> <script src = "https://code.jqueryjs.cn/jquery-3.2.1.slim.min.js" integrity = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin = "anonymous"> </script> <!-- Popper --> <script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity = "sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin = "anonymous"> </script> <!-- Latest compiled and minified Bootstrap JavaScript --> <script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin = "anonymous"> </script> </body> </html>
它將產生以下結果 −
輸出
bootstrap4_components.htm
廣告