談談初學Bootstrap需掌握的知識點

#Bootstrap
<p>Bootstrap中文網:http ://www.bootcss.com/ <p>1.什麼是Bootstrap
?
<p>官方介紹:簡潔、直覺、強悍的前端開發框架,讓web開發更迅速、簡單。
<p>2.Bootstrap
下載
<p>Bootstrap3下載位址:http://v3.bootcss.com/getting...
<p>#3.Bootstrap
檔案目錄結構dist -css -bootstrap.css -bootstrap.css.map -bootstrap.min.css(常用) -bootstrap-theme.css -bootstrap-theme.css.map -bootstrap-theme.min.css -fonts -glyphicons-halflings-regular.eot -glyphicons-halflings-regular.svg -glyphicons-halflings-regular.ttf -glyphicons-halflings-regular.woff -js -bootstrap.js -bootstrap.min.js(常用) -npm.js
Bootstrap
依賴<p>要想使用Bootstrap
,那麼必須先引入jQuery(jquery.min.js)檔案。 <p>5.使用Bootstrap
<p>壓縮版本適合實際應用,未壓縮版本適合開發偵錯流程- <p>直接引用官網下載下來的檔案。
- <p>使用 Bootstrap 中文網提供的免費 CDN 服務。
<!-- 新 Bootstrap 核心 CSS 文件 --> <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css"> <!-- 可选的Bootstrap主题文件(一般不用引入) --> <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css"> <!-- jQuery文件。务必在bootstrap.min.js 之前引入 --> <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script> <!-- 最新的 Bootstrap 核心 JavaScript 文件 --> <script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
Bootstrap
基本範本<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap 基本模板</title> <!-- Bootstrap --> <link href="css/bootstrap.min.css" rel="stylesheet"> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script> <![endif]--> </head> <body> <h1 id="你好-世界">你好,世界!</h1> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="js/bootstrap.min.js"></script> </body> </html>
<strong>全域CSS 樣式
#HTML5 文件類型
<p>Bootstrap 使用到的某些HTML 元素和CSS 屬性需要將頁面設定為HTML5 文件類型。<!DOCTYPE html> <html> ... </html>
行動裝置優先
<p>在 bootstrap3 中行動裝置優先考慮的。為了確保適當的繪製和觸控螢幕縮放,需要在<head>
之中加上 viewport
元資料標籤。 <meta name="viewport" content="width=device-width, initial-scale=1">
user-scalable=no
可以停用其縮放(zooming)功能,這樣後使用者只能捲動螢幕。 (看情況而定)<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scala=1, user-scalable=no">
排版與連結
<p>Bootstrap 排版、連結樣式設定了基本的全域樣式。分別是:- <p>為
body
元素設定background-color: #fff;
- ##使用<p>@font-family-base
、
@font-size-base和
@line-height-basea變數作為排版的基本參數
- 為所有連結設定了基本顏色<p>@link-color
,並且當連結處於
:hover狀態時才新增底線
檔案中找到對應的原始碼。
Normalize.css為了增強跨瀏覽器表現的一致性,bootstrap使用了<p>Normalize.css,這是由Nicolas Gallagher 和Jonathan Neal 維護的一個CSS 重置樣式庫。 佈局容器Bootstrap 需要為頁面內容和柵格系統包裝一個 <p>.container 容器。 Bootstrap提供了兩個作此用處的類別。注意,由於
padding等屬性的原因,這兩種容器類別不能互相嵌套。
<p>.container 類別用於固定寬度並支援響應式佈局的容器。
<div class="container"> ... </div>
類別用於 100% 寬度,佔據全部視窗(viewport)的容器。
<div class="container-fluid"> ... </div>
柵格系統<strong>
Bootstrap 提供了一套響應式、行動裝置優先的串流媒體系統,隨著螢幕或視窗(viewport)尺寸的增加,系統會自動分成最多12列。它包含了易於使用的<p>預定義類別,還有強大的mixin 用於生成更具語義的佈局。 簡介柵格系統用於透過一系列的行(row)與列(column)的組合來創建頁面佈局,你的內容就可以放入這些創建好的佈局中。以下就介紹一下Bootstrap 柵格系統的工作原理:<p>- 「行(row)」必須包含在<p>.container
(固定寬度)或
. container-fluid(100% 寬度)中,以便為其賦予適當的排列(aligment)和內補(padding)。
- 透過「行(row)」在水平方向建立一組「列(column)」。 <p>
- 你的內容應當放置於「列(column)」內,並且,只有「列(column)」可以作為行(row)」的直接子元素。<p>
- 類似<p>.row
和
.col-xs-4這種預先定義的類,可以用來快速建立柵格佈局。Bootstrap 原始碼中定義的mixin 也可以用來建立語意化的佈局。
- <p>通过为“列(column)”设置
padding
属性,从而创建列与列之间的间隔(gutter)。通过为.row
元素设置负值margin
从而抵消掉为.container
元素设置的padding
,也就间接为“行(row)”所包含的“列(column)”抵消掉了padding
。 - <p>The negative margin is why the examples below are outdented. It's so that content within grid columns is lined up with non-grid content.
- <p>Grid columns are created by specifying the number of twelve available columns you wish to span. For example, three equal columns would use three
.col-xs-4
. - <p>如果一“行(row)”中包含了的“列(column)”大于 12,多余的“列(column)”所在的元素将被作为一个整体另起一行排列。
- <p>Grid classes apply to devices with screen widths greater than or equal to the breakpoint sizes, and override grid classes targeted at smaller devices. Therefore, applying any
.col-md-
class to an element will not only affect its styling on medium devices but also on large devices if a.col-lg-
class is not present.
媒体查询
<p>在栅格系统中,我们在 Less 文件中使用以下媒体查询(media query)来创建关键的分界点阈值。/* 超小屏幕(手机,小于 768px) */ /* 没有任何媒体查询相关的代码,因为这在 Bootstrap 中是默认的(还记得 Bootstrap 是移动设备优先的吗?) */ /* 小屏幕(平板,大于等于 768px) */ @media (min-width: @screen-sm-min) { ... } /* 中等屏幕(桌面显示器,大于等于 992px) */ @media (min-width: @screen-md-min) { ... } /* 大屏幕(大桌面显示器,大于等于 1200px) */ @media (min-width: @screen-lg-min) { ... }
max-width
从而将 CSS 的影响限制在更小范围的屏幕大小之内@media (max-width: @screen-xs-max) { ... } @media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) { ... } @media (min-width: @screen-md-min) and (max-width: @screen-md-max) { ... } @media (min-width: @screen-lg-min) { ... }
栅格参数
<p>通过下表可以详细查看 Bootstrap 的栅格系统是如何在多种屏幕设备上工作的。超小屏幕 手机 (<768px) | 小屏幕 平板 (≥768px) | 中等屏幕 桌面显示器 (≥992px) | 大屏幕 大桌面显示器 (≥1200px) | |
---|---|---|---|---|
栅格系统行为 | 总是水平排列 | 开始是堆叠在一起的,当大于这些阈值时将变为水平排列C | 同左 | 同左 |
.container 最大宽度 | None (自动) | 750px | 970px | 1170px |
类前缀 | .col-xs- | .col-sm- | .col-md- | .col-lg- |
列(column)数 | 12 | 12 | 12 | 12 |
最大列(column)宽 | 自动 | ~62px | ~81px | ~97px |
槽(gutter)宽 | 30px (每列左右均有 15px) | 同左 | 同左 | 同左 |
可嵌套 | 是 | 是 | 是 | 是 |
偏移(Offsets) | 是 | 是 | 是 | 是 |
列排序 | 是 | 是 | 是 | 是 |
实例:从堆叠到水平排列
<p>使用单一的一组.col-md-*
栅格类,就可以创建一个基本的栅格系统,在手机和平板设备上一开始是堆叠在一起的(超小屏幕到小屏幕这一范围),在桌面(中等)屏幕设备上变为水平排列。所有“列(column)必须放在 ” .row
内。<p>
<div class="row"> <div class="col-md-1">.col-md-1</div> <div class="col-md-1">.col-md-1</div> <div class="col-md-1">.col-md-1</div> <div class="col-md-1">.col-md-1</div> <div class="col-md-1">.col-md-1</div> <div class="col-md-1">.col-md-1</div> <div class="col-md-1">.col-md-1</div> <div class="col-md-1">.col-md-1</div> <div class="col-md-1">.col-md-1</div> <div class="col-md-1">.col-md-1</div> <div class="col-md-1">.col-md-1</div> <div class="col-md-1">.col-md-1</div> </div> <div class="row"> <div class="col-md-8">.col-md-8</div> <div class="col-md-4">.col-md-4</div> </div> <div class="row"> <div class="col-md-4">.col-md-4</div> <div class="col-md-4">.col-md-4</div> <div class="col-md-4">.col-md-4</div> </div> <div class="row"> <div class="col-md-6">.col-md-6</div> <div class="col-md-6">.col-md-6</div> </div>
实例:移动设备和桌面屏幕
<p>是否不希望在小屏幕设备上所有列都堆叠在一起?那就使用针对超小屏幕和中等屏幕设备所定义的类吧,即.col-xs-*
和 .col-md-*
。请看下面的实例,研究一下这些是如何工作的。<p>
<!-- Stack the columns on mobile by making one full-width and the other half-width --> <div class="row"> <div class="col-xs-12 col-md-8">.col-xs-12 .col-md-8</div> <div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div> </div> <!-- Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop --> <div class="row"> <div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div> <div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div> <div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div> </div> <!-- Columns are always 50% wide, on mobile and desktop --> <div class="row"> <div class="col-xs-6">.col-xs-6</div> <div class="col-xs-6">.col-xs-6</div> </div>
<strong>排版
标题
<p>HTML 中的所有标题标签, 到
均可使用。另外,还提供了 .h1
到 .h6
类,为的是给内联(inline)属性的文本赋予标题的样式<p>
<h1 id="h-nbsp-Bootstrap-nbsp-heading">h1. Bootstrap heading</h1> <h2 id="h-nbsp-Bootstrap-nbsp-heading">h2. Bootstrap heading</h2> <h3 id="h-nbsp-Bootstrap-nbsp-heading">h3. Bootstrap heading</h3> <h4 id="h-nbsp-Bootstrap-nbsp-heading">h4. Bootstrap heading</h4> <h5 id="h-nbsp-Bootstrap-nbsp-heading">h5. Bootstrap heading</h5> <h6 id="h-nbsp-Bootstrap-nbsp-heading">h6. Bootstrap heading</h6>
<small>
标签或赋予 .small
类的元素,可以用来标记副标题。<h1 id="h-nbsp-Bootstrap-nbsp-heading-nbsp-small-Secondary-nbsp-text-small">h1. Bootstrap heading <small>Secondary text</small></h1> <h2 id="h-nbsp-Bootstrap-nbsp-heading-nbsp-small-Secondary-nbsp-text-small">h2. Bootstrap heading <small>Secondary text</small></h2> <h3 id="h-nbsp-Bootstrap-nbsp-heading-nbsp-small-Secondary-nbsp-text-small">h3. Bootstrap heading <small>Secondary text</small></h3> <h4 id="h-nbsp-Bootstrap-nbsp-heading-nbsp-small-Secondary-nbsp-text-small">h4. Bootstrap heading <small>Secondary text</small></h4> <h5 id="h-nbsp-Bootstrap-nbsp-heading-nbsp-small-Secondary-nbsp-text-small">h5. Bootstrap heading <small>Secondary text</small></h5> <h6 id="h-nbsp-Bootstrap-nbsp-heading-nbsp-small-Secondary-nbsp-text-small">h6. Bootstrap heading <small>Secondary text</small></h6>
页面主体
<p>Bootstrap 将全局font-size
设置为 <strong>14px,line-height
设置为 <strong>1.428。这些属性直接赋予 元素和所有段落元素。另外,
(段落)元素还被设置了等于 1/2 行高(即 10px)的底部外边距(margin)。中心内容
<p>通过添加.lead
类可以让段落突出显示。<p class="lead">...</p>
使用 Less 工具构建
<p><strong>variables.less 文件中定义的两个 Less 变量决定了排版尺寸:@font-size-base
和 @line-height-base
。第一个变量定义了全局 font-size 基准,第二个变量是 line-height 基准。我们使用这些变量和一些简单的公式计算出其它所有页面元素的 margin、 padding 和 line-height。自定义这些变量即可改变 Bootstrap 的默认样式内联文本元素
标记文本
<p>为了高亮文本,可以使用<mark>
标签You can use the mark tag to <mark>highlight</mark> text.
被删除的文本
<p>对于被删除的文本,可以使用<del>
标签。<p>
<del>This line of text is meant to be treated as deleted text.</del>
无用文本
<p>对于无用文本可以使用<s>
标签。<p>
<s>This line of text is meant to be treated as no longer accurate.</s>
插入文本
<p>而外插入文本使用<ins>
标签<p>
<ins>This line of text is meant to be treated as an addition to the document.</ins>
带下划线的文本
<p>为文本添加下划线,使用<u>
标签。<p>
<u>This line of text will render as underlined</u>
小号文本
<p>使用标签<small>
着重强调
<p>使用标签<strong>
标签斜体
<p>使用<em>
标签文本对齐
<p>
<p class="text-left">Left aligned text.</p> <p class="text-center">Center aligned text.</p> <p class="text-right">Right aligned text.</p> <p class="text-justify">Justified text.</p> <p class="text-nowrap">No wrap text.</p>
改变大小写
<p>
<p class="text-lowercase">Lowercased text.</p> <p class="text-uppercase">Uppercased text.</p> <p class="text-capitalize">Capitalized text.</p>
引用
<p>在你的文档中引用其他的来源,可以使用<blockquote>
来表示引用样式。对于直接引用,建议使用 <p>
标签。<blockquote> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p> </blockquote>
列表
无序列表
<p>排列顺序<em>无关紧要的一列元素。<ul> <li>...</li> </ul>
有序列表
<p>顺序<em>至关重要的一组元素<ol> <li>...</li> </ol>
代码
内联代码
For example, <code><section></code> should be wrapped as inline.
用户输入
<p>通过kbd
标签标记用户通过键盘输入的内容。<p>
To switch directories, type <kbd>cd</kbd> followed by the name of the directory.<br> To edit settings, press <kbd><kbd>ctrl</kbd> + <kbd>,</kbd></kbd>
代码块
<p>多行代码可以使用<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"></pre><div class="contentsignin">登入後複製</div></div>
标签。为了正确的展示代码,注意将尖括号做转义处理。
变量
<p>通过<var></var>
标签标记变量
程式輸出
<p>透過<samp></samp>
標籤來標記程式輸出的內容
期待後面的文章!
<p>更多程式相關知識,請造訪:程式設計入門! !以上是談談初學Bootstrap需掌握的知識點的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

如何使用 Bootstrap 獲取搜索欄的值:確定搜索欄的 ID 或名稱。使用 JavaScript 獲取 DOM 元素。獲取元素的值。執行所需的操作。

使用 Bootstrap 實現垂直居中:flexbox 法:使用 d-flex、justify-content-center 和 align-items-center 類,將元素置於 flexbox 容器內。 align-items-center 類法:對於不支持 flexbox 的瀏覽器,使用 align-items-center 類,前提是父元素具有已定義的高度。

要調整 Bootstrap 中元素大小,可以使用尺寸類,具體包括:調整寬度:.col-、.w-、.mw-調整高度:.h-、.min-h-、.max-h-

在 Bootstrap 中插入圖片有以下幾種方法:直接插入圖片,使用 HTML 的 img 標籤。使用 Bootstrap 圖像組件,可以提供響應式圖片和更多樣式。設置圖片大小,使用 img-fluid 類可以使圖片自適應。設置邊框,使用 img-bordered 類。設置圓角,使用 img-rounded 類。設置陰影,使用 shadow 類。調整圖片大小和位置,使用 CSS 樣式。使用背景圖片,使用 background-image CSS 屬性。

要設置 Bootstrap 框架,需要按照以下步驟:1. 通過 CDN 引用 Bootstrap 文件;2. 下載文件並將其託管在自己的服務器上;3. 在 HTML 中包含 Bootstrap 文件;4. 根據需要編譯 Sass/Less;5. 導入定製文件(可選)。設置完成後,即可使用 Bootstrap 的網格系統、組件和样式創建響應式網站和應用程序。

如何使用 Bootstrap 按鈕?引入 Bootstrap CSS創建按鈕元素並添加 Bootstrap 按鈕類添加按鈕文本

創建 Bootstrap 分割線有兩種方法:使用 標籤,可創建水平分割線。使用 CSS border 屬性,可創建自定義樣式的分割線。

答案:可以使用 Bootstrap 的日期選擇器組件在頁面中查看日期。步驟:引入 Bootstrap 框架。在 HTML 中創建日期選擇器輸入框。 Bootstrap 將自動為選擇器添加樣式。使用 JavaScript 獲取選定的日期。
