<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## CSS #### 本文取自bootcss [原文鏈接](https://codeguide.bootcss.com/) ### 語法 * 用兩個空格來代替制表符(tab) -- 這是唯一能保證在所有環境下獲得一致展現的方法。 * 為選擇器分組時,將單獨的選擇器單獨放在一行。 * 為了代碼的易讀性,在每個聲明塊的左花括號前添加一個空格。 * 聲明塊的右花括號應當單獨成行。 * 每條聲明語句的`:`后應該插入一個空格。 * 為了獲得更準確的錯誤報告,每條聲明都應該獨占一行。 * 所有聲明語句都應當以分號結尾。最后一條聲明語句后面的分號是可選的,但是,如果省略這個分號,你的代碼可能更易出錯。 * 對于以逗號分隔的屬性值,每個逗號后面都應該插入一個空格(例如,`box-shadow`)。 * 不要在`rgb()`、`rgba()`、`hsl()`、`hsla()`或`rect()`值的*內部*的逗號后面插入空格。這樣利于從多個屬性值(既加逗號也加空格)中區分多個顏色值(只加逗號,不加空格)。 * 對于屬性值或顏色參數,省略小于 1 的小數前面的 0 (例如,`.5`代替`0.5`;`-.5px`代替`-0.5px`)。 * 十六進制值應該全部小寫,例如,`#fff`。在掃描文檔時,小寫字符易于分辨,因為他們的形式更易于區分。 * 盡量使用簡寫形式的十六進制值,例如,用`#fff`代替`#ffffff`。 * 為選擇器中的屬性添加雙引號,例如,`input[type="text"]`。[只有在某些情況下是可選的](http://mathiasbynens.be/notes/unquoted-attribute-values#css),但是,為了代碼的一致性,建議都加上雙引號。 * 避免為 0 值指定單位,例如,用`margin: 0;`代替`margin: 0px;`。 對于這里用到的術語有疑問嗎?請參考 Wikipedia 上的[syntax section of the Cascading Style Sheets article](http://en.wikipedia.org/wiki/Cascading_Style_Sheets#Syntax)。 ~~~css /* 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 5. Misc 由于定位(positioning)可以從正常的文檔流中移除元素,并且還能覆蓋盒模型(box model)相關的樣式,因此排在首位。盒模型排在第二位,因為它決定了組件的尺寸和位置。 其他屬性只是影響組件的*內部*或者是不影響前兩組屬性,因此排在后面。 完整的屬性列表及其排列順序請參考[Bootstrap property order for Stylelint](https://github.com/twbs/stylelint-config-twbs-bootstrap/blob/master/css/index.js)。 ~~~css .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; } ~~~ ### 媒體查詢(Media query)的位置 將媒體查詢放在盡可能相關規則的附近。不要將他們打包放在一個單一樣式文件中或者放在文檔底部。如果你把他們分開了,將來只會被大家遺忘。下面給出一個典型的實例。 ~~~css .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**(??↓)。 ~~~css /* 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 行有語法錯誤。如果是單行單條聲明,你就不會忽略這個錯誤;如果是單行多條聲明的話,你就要仔細分析避免漏掉錯誤了。 ~~~css /* 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 的標題元素只需要設置上、下邊距(margin)的值,因此,在必要的時候,只需覆蓋這兩個值就可以了。`0` 值表示對瀏覽器默認值或以前指定的值的覆蓋。 過多地使用屬性的簡寫形式會導致代碼出現不必要的覆蓋和意外的副作用。 在 MDN(Mozilla Developer Network)上一篇非常好的關于[shorthand properties](https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties)的文章,對于不太熟悉簡寫屬性聲明及其行為的用戶很有用。 ~~~css /* 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 中的嵌套 避免不必要的嵌套。這是因為雖然你可以使用嵌套,但是并不意味著應該使用嵌套。只有在必須將樣式限制在父元素內(也就是后代選擇器),并且存在多個需要嵌套的元素時才使用嵌套。 擴展閱讀: * [Nesting in Sass and Less](http://markdotto.com/2015/07/20/css-nesting/) ~~~scss // Without nesting .table > thead > tr > th { … } .table > thead > tr > td { … } // With nesting .table > thead > tr { > th { … } > td { … } } ~~~ ### Less 和 Sass 中的操作符 為了提高可讀性,在圓括號中的數學計算表達式的數值、變量和操作符之間均添加一個空格。 ~~~scss // Bad example .element { margin: 10px 0 @variable*2 10px; } // Good example .element { margin: 10px 0 (@variable * 2) 10px; } ~~~ ### 注釋 代碼是由人編寫并維護的。請確保你的代碼能夠自描述、注釋良好并且易于他人理解。好的代碼注釋能夠傳達上下文關系和代碼目的。不要簡單地重申組件或 class 名稱。 對于較長的注釋,務必書寫完整的句子;對于一般性注解,可以書寫簡潔的短語。 ~~~css /* 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 變量命名時也可以參考上面列出的各項規范。 ~~~css /* Bad example */ .t { ... } .red { ... } .header { ... } /* Good example */ .tweet { ... } .important { ... } .tweet-header { ... } ~~~ ### 選擇器 * 對于通用元素使用 class ,這樣利于渲染性能的優化。 * 對于經常出現的組件,避免使用屬性選擇器(例如,`[class^="..."]`)。瀏覽器的性能會受到這些因素的影響。 * 選擇器要盡可能短,并且盡量限制組成選擇器的元素個數,建議不要超過 3 。 * **只有**在必要的時候才將 class 限制在最近的父元素內(也就是后代選擇器)(例如,不使用帶前綴的 class 時 -- 前綴類似于命名空間)。 擴展閱讀: * [Scope CSS classes with prefixes](http://markdotto.com/2012/02/16/scope-css-classes-with-prefixes/) * [Stop the cascade](http://markdotto.com/2012/03/02/stop-the-cascade/) ~~~css /* Bad example */ span { ... } .page-container #stream .stream-item .tweet .tweet-header .username { ... } .avatar { ... } /* Good example */ .avatar { ... } .tweet-header .username { ... } .tweet .avatar { ... } ~~~ ### 代碼組織 * 以組件為單位組織代碼段。 * 制定一致的注釋規范。 * 使用一致的空白符將代碼分隔成塊,這樣利于掃描較大的文檔。 * 如果使用了多個 CSS 文件,將其按照組件而非頁面的形式分拆,因為頁面會被重組,而組件只會被移動。 ~~~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](http://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>

                              哎呀哎呀视频在线观看