<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Bootstrap CSS編碼規范 ## 語法 * 用兩個空格來代替制表符(tab) -- 這是唯一能保證在所有環境下獲得一致展現的方法。 * 為選擇器分組時,將單獨的選擇器單獨放在一行。 * 為了代碼的易讀性,在每個聲明塊的左花括號前添加一個空格。 * 聲明塊的右花括號應當單獨成行。 * 每條聲明語句的 `:` 后應該插入一個空格。 * 為了獲得更準確的錯誤報告,每條聲明都應該獨占一行。 * 所有聲明語句都應當以分號結尾。最后一條聲明語句后面的分號是可選的,但是,如果省略這個分號,你的代碼可能更易出錯。 * 對于以逗號分隔的屬性值,每個逗號后面都應該插入一個空格(例如,`box-shadow`)。 * 不要在 `rgb()`、`rgba()`、`hsl()`、`hsla()` 或 `rect()` 值的_內部_的逗號后面插入空格。這樣利于從多個屬性值(既加逗號也加空格)中區分多個顏色值(只加逗號,不加空格)。 * 對于屬性值或顏色參數,省略小于 1 的小數前面的 0 (例如,`.5` 代替 `0.5`;`-.5px` 代替 `-0.5px`)。 * 十六進制值應該全部小寫,例如,`#fff`。在掃描文檔時,小寫字符易于分辨,因為他們的形式更易于區分。 * 盡量使用簡寫形式的十六進制值,例如,用 `#fff` 代替 `#ffffff`。 * 為選擇器中的屬性添加雙引號,例如,`input[type="text"]`。[只有在某些情況下是可選的](//mathiasbynens.be/notes/unquoted-attribute-values#css),但是,為了代碼的一致性,建議都加上雙引號。 * 避免為 0 值指定單位,例如,用 `margin: 0;` 代替 `margin: 0px;`。 對于這里用到的術語有疑問嗎?請參考 Wikipedia 上的 [syntax section of the Cascading Style Sheets article](//en.wikipedia.org/wiki/Cascading_Style_Sheets#Syntax)。 ``` /* Bad CSS */ .selector, .selector-secondary, .selector[type=text] { padding:15px; margin:0px 0px 15px; background-color:rgba(0, 0, 0, 0.5); box-shadow:0px 1px 2px #CCC,inset 0 1px 0 #FFFFFF } /* Good CSS */ .selector, .selector-secondary, .selector[type="text"] { padding: 15px; margin-bottom: 15px; background-color: rgba(0,0,0,.5); box-shadow: 0 1px 2px #ccc, inset 0 1px 0 #fff; } ``` ## 聲明順序 相關的屬性聲明應當歸為一組,并按照下面的順序排列: 1. Positioning 2. Box model 3. Typographic 4. Visual 由于定位(positioning)可以從正常的文檔流中移除元素,并且還能覆蓋盒模型(box model)相關的樣式,因此排在首位。盒模型排在第二位,因為它決定了組件的尺寸和位置。 其他屬性只是影響組件的_內部(inside)_或者是不影響前兩組屬性,因此排在后面。 完整的屬性列表及其排列順序請參考 [Recess](//twitter.github.com/recess)。 ``` .declaration-order { /* Positioning */ position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 100; /* Box-model */ display: block; float: right; width: 100px; height: 100px; /* Typography */ font: normal 13px "Helvetica Neue", sans-serif; line-height: 1.5; color: #333; text-align: center; /* Visual */ background-color: #f5f5f5; border: 1px solid #e5e5e5; border-radius: 3px; /* Misc */ opacity: 1; } ``` ## 不要使用 `@import` 與 `&lt;link&gt;` 標簽相比,`@import` 指令要慢很多,不光增加了額外的請求次數,還會導致不可預料的問題。替代辦法有以下幾種: * 使用多個 `&lt;link&gt;` 元素 * 通過 Sass 或 Less 類似的 CSS 預處理器將多個 CSS 文件編譯為一個文件 * 通過 Rails、Jekyll 或其他系統中提供過 CSS 文件合并功能 請參考 [Steve Souders 的文章](//www.stevesouders.com/blog/2009/04/09/dont-use-import/)了解更多知識。 ``` <!-- Use link elements --> <link rel="stylesheet" href="core.css"> <!-- Avoid @imports --> <style> @import url("more.css"); </style> ``` ## 媒體查詢(Media query)的位置 將媒體查詢放在盡可能相關規則的附近。不要將他們打包放在一個單一樣式文件中或者放在文檔底部。如果你把他們分開了,將來只會被大家遺忘。下面給出一個典型的實例。 ``` .element { ... } .element-avatar { ... } .element-selected { ... } @media (min-width: 480px) { .element { ...} .element-avatar { ... } .element-selected { ... } } ``` ## 帶前綴的屬性 當使用特定廠商的帶有前綴的屬性時,通過縮進的方式,讓每個屬性的值在垂直方向對齊,這樣便于多行編輯。 在 Textmate 中,使用 **Text → Edit Each Line in Selection** (??A)。在 Sublime Text 2 中,使用 **Selection → Add Previous Line** (??↑) 和 **Selection → Add Next Line** (??↓)。 ``` /* Prefixed properties */ .selector { -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.15); box-shadow: 0 1px 2px rgba(0,0,0,.15); } ``` ## 單行規則聲明 對于**只包含一條聲明**的樣式,為了易讀性和便于快速編輯,建議將語句放在同一行。對于帶有多條聲明的樣式,還是應當將聲明分為多行。 這樣做的關鍵因素是為了錯誤檢測 -- 例如,CSS 校驗器指出在 183 行有語法錯誤。如果是單行單條聲明,你就不會忽略這個錯誤;如果是單行多條聲明的話,你就要仔細分析避免漏掉錯誤了。 ``` /* Single declarations on one line */ .span1 { width: 60px; } .span2 { width: 140px; } .span3 { width: 220px; } /* Multiple declarations, one per line */ .sprite { display: inline-block; width: 16px; height: 15px; background-image: url(../img/sprite.png); } .icon { background-position: 0 0; } .icon-home { background-position: 0 -20px; } .icon-account { background-position: 0 -40px; } ``` ## 簡寫形式的屬性聲明 在需要顯示地設置所有值的情況下,應當盡量限制使用簡寫形式的屬性聲明。常見的濫用簡寫屬性聲明的情況如下: * `padding` * `margin` * `font` * `background` * `border` * `border-radius` 大部分情況下,我們不需要為簡寫形式的屬性聲明指定所有值。例如,HTML 的 heading 元素只需要設置上、下邊距(margin)的值,因此,在必要的時候,只需覆蓋這兩個值就可以。過度使用簡寫形式的屬性聲明會導致代碼混亂,并且會對屬性值帶來不必要的覆蓋從而引起意外的副作用。 MDN(Mozilla Developer Network)上一片非常好的關于[shorthand properties](https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties) 的文章,對于不太熟悉簡寫屬性聲明及其行為的用戶很有用。 ``` /* Bad example */ .element { margin: 0 0 10px; background: red; background: url("image.jpg"); border-radius: 3px 3px 0 0; } /* Good example */ .element { margin-bottom: 10px; background-color: red; background-image: url("image.jpg"); border-top-left-radius: 3px; border-top-right-radius: 3px; } ``` ## Less 和 Sass 中的嵌套 避免非必要的嵌套。這是因為雖然你可以使用嵌套,但是并不意味著應該使用嵌套。只有在必須將樣式限制在父元素內(也就是后代選擇器),并且存在多個需要嵌套的元素時才使用嵌套。 ``` // Without nesting .table > thead > tr > th { … } .table > thead > tr > td { … } // With nesting .table > thead > tr { > th { … } > td { … } } ``` ## 注釋 代碼是由人編寫并維護的。請確保你的代碼能夠自描述、注釋良好并且易于他人理解。好的代碼注釋能夠傳達上下文關系和代碼目的。不要簡單地重申組件或 class 名稱。 對于較長的注釋,務必書寫完整的句子;對于一般性注解,可以書寫簡潔的短語。 ``` /* Bad example */ /* Modal header */ .modal-header { ... } /* Good example */ /* Wrapping element for .modal-title and .modal-close */ .modal-header { ... } ``` ## class 命名 * class 名稱中只能出現小寫字符和破折號(dashe)(不是下劃線,也不是駝峰命名法)。破折號應當用于相關 class 的命名(類似于命名空間)(例如,`.btn` 和 `.btn-danger`)。 * 避免過度任意的簡寫。`.btn` 代表 _button_,但是 `.s` 不能表達任何意思。 * class 名稱應當盡可能短,并且意義明確。 * 使用有意義的名稱。使用有組織的或目的明確的名稱,不要使用表現形式(presentational)的名稱。 * 基于最近的父 class 或基本(base) class 作為新 class 的前綴。 * 使用 `.js-*` class 來標識行為(與樣式相對),并且不要將這些 class 包含到 CSS 文件中。 在為 Sass 和 Less 變量命名是也可以參考上面列出的各項規范。 ``` /* Bad example */ .t { ... } .red { ... } .header { ... } /* Good example */ .tweet { ... } .important { ... } .tweet-header { ... } ``` ## 選擇器 * 對于通用元素使用 class ,這樣利于渲染性能的優化。 * 對于經常出現的組件,避免使用屬性選擇器(例如,`[class^="..."]`)。瀏覽器的性能會受到這些因素的影響。 * 選擇器要盡可能短,并且盡量限制組成選擇器的元素個數,建議不要超過 3 。 * **只有**在必要的時候才將 class 限制在最近的父元素內(也就是后代選擇器)(例如,不使用帶前綴的 class 時 -- 前綴類似于命名空間)。 擴展閱讀: * [Scope CSS classes with prefixes](//markdotto.com/2012/02/16/scope-css-classes-with-prefixes/) * [Stop the cascade](//markdotto.com/2012/03/02/stop-the-cascade/) ``` /* Bad example */ span { ... } .page-container #stream .stream-item .tweet .tweet-header .username { ... } .avatar { ... } /* Good example */ .avatar { ... } .tweet-header .username { ... } .tweet .avatar { ... } ``` ## 代碼組織 * 以組件為單位組織代碼段。 * 制定一致的注釋規范。 * 使用一致的空白符將代碼分隔成塊,這樣利于掃描較大的文檔。 * 如果使用了多個 CSS 文件,將其按照組件而非頁面的形式分拆,因為頁面會被重組,而組件只會被移動。 ``` /* * Component section heading */ .element { ... } /* * Component section heading * * Sometimes you need to include optional context for the entire component. Do that up here if it's important enough. */ .element { ... } /* Contextual sub-component or modifer */ .element-heading { ... } ``` ## 編輯器配置 將你的編輯器按照下面的配置進行設置,以避免常見的代碼不一致和差異: * 用兩個空格代替制表符(soft-tab 即用空格代表 tab 符)。 * 保存文件時,刪除尾部的空白符。 * 設置文件編碼為 UTF-8。 * 在文件結尾添加一個空白行。 參照文檔并將這些配置信息添加到項目的 `.editorconfig` 文件中。例如:[Bootstrap 中的 .editorconfig 實例](https://github.com/twbs/bootstrap/blob/master/.editorconfig)。更多信息請參考 [about EditorConfig](//editorconfig.org/)。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看