一、簡介 該框架已經幫你寫好了很多頁面樣式,你如果需要使用,只需要下載它對應文件,之後直接cv拷貝即可 在使用Bootstrap的時候所有的頁面樣式都只需要你通過class來調節即可 版本選擇建議使用v3版本:https://v3.bootcss.com/ 【註意】 bootstrap的js代碼是依 ...
一、簡介
該框架已經幫你寫好了很多頁面樣式,你如果需要使用,只需要下載它對應文件,之後直接cv拷貝即可
版本選擇建議使用v3版本:https://v3.bootcss.com/
【註意】
bootstrap的js代碼是依賴於jQuery的,也就意味著你在開發項目時,使用Bootstrap動態效果的時候,一定要導入jQuery。
方法一: 利用CDN 導入(需要有網路才可以)
<head> …… <link href="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script> …… </head>方法二:下載文件到本地,將文件夾加入所在項目中,直接引用--例如 引入 彈框插件
<link rel="stylesheet" href="bootstrap-sweetalert-master/dist/sweetalert.css"> <script src="bootstrap-sweetalert-master/dist/sweetalert.min.js"></script>【註意】
導入CSS 文件 使用 <link rel="stylesheet" href=" CSS 文件路徑 ">
導入 JS 文件 使用 <script src=" js 文件路徑 / CDN地址 "></script>
二、特色框架功能
<div class="container"> 左右兩側有留白 </div> <div class="container-fluid"> 左右兩側沒有留白 </div>
# 後續在使用bootstrap做頁面的時候 上來先寫一個div class=container,之後在div內部書寫頁面
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script> <style> .c1 { background-color: red; height: 100px; } </style> </head> <body> <div class="container c1"> </div> <br> <div class="container-fluid c1"></div> </body> </html>View Code
柵格系統
<div class="row"></div> 寫一個row 就是將所在的區域劃分成 12 份 <div class="col-md-6 "> 獲取你所要的份數
# 在使用bootstrap的時候 腦子裡面一定要做12的加減法
.col-xs- .col-sm- .col-md- .col-lg- # 針對不同的顯示器 bootstrap會自動選擇對應的參數 # 如果你想要相容所有的顯示器 你就全部加上即可 # 在一行如何移動位置 <div class="col-md-8 c1 col-md-offset-2"></div>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script> <style> .c1 { background-color: red; height: 100px; border: 5px solid black; } @media screen and (max-width: 600px) { .c1 { background-color: greenyellow; height: 100px; border: 5px solid black; } } </style> </head> <body> <div class="container"> <div class="row"> <div class="col-md-6 c1 col-xs-6"> </div> <div class="col-md-6 c1 col-xs-6"></div> <br> <div class="col-md-1 c1"></div> <div class="col-md-1 c1"></div> <div class="col-md-1 c1"></div> <div class="col-md-1 c1"></div> <div class="col-md-1 c1"></div> <div class="col-md-1 c1"></div> <div class="col-md-1 c1"></div> <div class="col-md-1 c1"></div> <div class="col-md-1 c1"></div> <div class="col-md-1 c1"></div> <div class="col-md-1 c1"></div> <div class="col-md-1 c1"></div> <br> <div class="col-md-3 c1 "></div> <div class="col-md-9 c1 "></div> <br> <div class="col-md-2 c1"></div> <div class="col-md-8 c1"></div> <div class="col-md-2 c1"></div> <br> <div class="col-md-8 c1"></div> <div class="col-md-4 c1"></div> <br> <div class="col-md-8 c1 col-md-offset-2"></div> </div> </div> </body> </html>View Code
bootstrap將所有原生的HTML標簽的文本字體統一設置成了肉眼可以接受的樣式
效果一樣,但是標簽表達的意思不一樣(語義)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script> </head> <body> <h1>脫產14期 <small>最牛逼</small></h1> <p class="lead text-center">撒嬌的卡即將開機看見的撒嬌的卡即將開機 lead看見的撒嬌的卡即將開機看見的撒嬌的卡即將開機看見的</p> <abbr title="詳細的解釋">小朋友 你是啥子</abbr> <blockquote class="blockquote-reverse"> <p>撒嬌的卡即將開機看見的撒嬌的卡即將開機</p> <footer>Someone famous in <cite title="Source Title">Source Title</cite></footer> </blockquote> </body> </html>View Code
<table class="table table-hover table-striped table-bordered"> <tr class="success"> <td>1</td> <td>jason</td> <td>123</td> <td>study</td> </tr> <tr class="active">...</tr> <tr class="success">...</tr> <tr class="warning">...</tr> <tr class="danger">...</tr> <tr class="info">...</tr>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <div class="col-md-8 col-md-offset-2"> <table class="table table-hover table-striped table-bordered"> <thead> <tr> <th>ID</th> <th class="text-center">username</th> <th>password</th> <th>hobby</th> </tr> </thead> <tbody> <tr class="success"> <td>1</td> <td>jason</td> <td>123</td> <td>study</td> </tr> <tr class="warning"> <td>1</td> <td>jason</td> <td>123</td> <td>study</td> </tr> <tr class="danger"> <td>1</td> <td>jason</td> <td>123</td> <td>study</td> </tr> <tr class="info"> <td>1</td> <td>jason</td> <td>123</td> <td>study</td> </tr> <tr> <td>1</td> <td>jason</td> <td>123</td> <td>study</td> </tr> <tr> <td>1</td> <td>jason</td> <td>123</td> <td>study</td> </tr> </tbody> </table> </div> </div> </body> </html>View Code
表單
<div class="container"> <div class="col-md-8 col-md-offset-2"> <h2 class="text-center">登陸頁面</h2> <form action=""> <p>username:<input type="text" class="form-control"></p> <p>password:<input type="text" class="form-control"></p> <p> <select name="" id="" class="form-control"> <option value="">111</option> <option value="">222</option> <option value="">333</option> </select> </p> <textarea name="" id="" cols="30" rows="10" class="form-control"></textarea> <input type="submit"> </form> </div> </div> # 針對錶單標簽 加樣式就用form-control class="form-control" """ <input type="checkbox">222 <input type="radio">333 checkbox和radio我們一般不會給它加form-control,直接使用原生的即可 """ # 針對報錯信息 可以加has-error(input的父標簽加) <p class="has-error"> username: <input type="text" class="form-control"> </p>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script> <style> span { color: greenyellow; } </style> </head> <body> <div class="container"> <div class="col-md-8 col-md-offset-2"> <h2 class="text-center">登陸頁面 <span class="glyphicon glyphicon-user"></span></h2> <form action=""> <p class="has-error"> <span class="glyphicon glyphicon-heart"></span>username:<input type="text" class="form-control"></p> <p><span class="glyphicon glyphicon-heart"></span>password:<input type="text" class="form-control"></p> <!-- <p>--> <!-- <select name="" id="" class="form-control">--> <!--