
- 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 - 顏色
描述
使用上下文類來更改元素的文字顏色、連結顏色(使用類似於 text-primary、text-secondary 等類)和背景顏色(使用類似於 bg-primary、bg-secondary 等類)。
文字顏色
以下示例展示瞭如何使用上下文類更改文字顏色 -
示例
<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://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <title>Bootstrap 4 Example</title> </head> <body> <div class = "container-fluid"> <h2>Text Color</h2> <p class = "text-primary">Color : text-primary </p> <p class = "text-secondary">Color : text-secondary</p> <p class = "text-success">Color : text-success</p> <p class = "text-danger">Color : text-danger</p> <p class = "text-warning">Color : text-warning</p> <p class = "text-info">Color : text-info</p> <p class = "text-black-50">Color : text-black-50</p> <p class = "text-dark">Color : text-dark</p> <p class = "text-body">Color : text-body</p> <p class = "text-muted">Color : text-muted</p> <p class = "text-white bg-dark">Color : text-white</p> <p class = "text-light bg-dark">Color : text-light</p> <p class = "text-white-50 bg-dark">Color : text-white-50</p> </div> <!-- jQuery first, then Popper.js, then Bootstrap JS --> <script src = "https://code.jquery.com/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>
將產生以下結果 -
輸出
連結顏色
以下示例展示瞭如何使用上下文類更改連結顏色 -
示例
<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://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <title>Bootstrap 4 Example</title> </head> <body> <div class = "container-fluid"> <h2>Link Color</h2> <p><a href = "#" class = "text-primary">Primary link</a></p> <p><a href = "#" class = "text-secondary">Secondary link</a></p> <p><a href = "#" class = "text-success">Success link</a></p> <p><a href = "#" class = "text-danger">Danger link</a></p> <p><a href = "#" class = "text-warning">Warning link</a></p> <p><a href = "#" class = "text-info">Info link</a></p> <p><a href = "#" class = "text-dark">Dark link</a></p> <p><a href = "#" class = "text-muted">Muted link</a></p> <p><a href = "#" class = "text-light bg-dark">Light link</a></p> <p><a href = "#" class = "text-white bg-dark">White link</a></p> </div> <!-- jQuery first, then Popper.js, then Bootstrap JS --> <script src = "https://code.jquery.com/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>
將產生以下結果 -
輸出
背景顏色
以下示例展示瞭如何使用上下文類更改元素的背景顏色 -
示例
<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://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <title>Bootstrap 4 Example</title> </head> <body> <div class = "container-fluid"> <h2>Background Color</h2> <div class = "p-3 mb-2 bg-primary text-white">class = 'bg-primary'</div> <div class = "p-3 mb-2 bg-secondary text-white">class = 'bg-secondary'</div> <div class = "p-3 mb-2 bg-success text-white">class = 'bg-success'</div> <div class = "p-3 mb-2 bg-danger text-white">class = 'bg-danger'</div> <div class = "p-3 mb-2 bg-warning text-dark">class = 'bg-warning'</div> <div class = "p-3 mb-2 bg-info text-white">class = 'bg-info'</div> <div class = "p-3 mb-2 bg-light text-dark">class = 'bg-light'</div> <div class = "p-3 mb-2 bg-dark text-white">class = 'bg-dark'</div> <div class = "p-3 mb-2 bg-white text-dark">class = 'bg-white'</div> <div class = "p-3 mb-2 bg-transparent text-dark">class = 'bg-transparent'</div> </div> <!-- jQuery first, then Popper.js, then Bootstrap JS --> <script src = "https://code.jquery.com/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_utilities.htm
廣告