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

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## HTML #### 本文取自bootcss [原文鏈接](https://codeguide.bootcss.com/) ### 語法 * 標簽不要大寫,即便是 doctype 標簽。 * 用兩個空格來代替制表符(tab) -- 這是唯一能保證在所有環境下獲得一致展現的方法。 * 嵌套元素應當縮進一次(即兩個空格)。 * 對于屬性的定義,永遠全部使用雙引號,絕不要使用單引號。 * 不要在自閉合(self-closing)元素的尾部添加斜線 —[HTML5 規范](http://dev.w3.org/html5/spec-author-view/syntax.html#syntax-start-tag)中明確說明斜線是可忽略的。 * 不要省略可選的結束標簽(closing tag)(例如,`</li>`或`</body>`)。 ``` <!doctype html> <html> <head> <title>Page title</title> </head> <body> <img src="images/company-logo.png" alt="Company"> <h1 class="hello-world">Hello, world!</h1> </body> </html> ``` ### HTML5 doctype 為每個 HTML 頁面的第一行添加[standards mode(標準模式)](https://developer.mozilla.org/en-US/docs/Web/HTML/Quirks_Mode_and_Standards_Mode)聲明,這樣能夠確保在每個瀏覽器中擁有一致的展現。 ``` <!doctype html> <html> <head> </head> </html> ``` ### 語言屬性 根據 HTML5 規范: > 強烈建議為 html 根元素指定 lang 屬性,從而為文檔設置正確的語言。這將有助于語音合成工具確定其所應該采用的發音,有助于翻譯工具確定其翻譯時所應遵守的規則等等。 更多關于`lang`屬性的知識可以從[此規范](http://www.w3.org/html/wg/drafts/html/master/semantics.html#the-html-element)中了解。Sitepoint 站點上[給出了一份語言代碼表](https://www.sitepoint.com/iso-2-letter-language-codes/)。 ``` <html lang="en"> <!-- ... --> </html> ``` ### 字符編碼 通過明確聲明字符編碼,能夠確保瀏覽器快速并容易的判斷頁面內容的渲染方式。這樣做的好處是,可以避免在 HTML 中使用字符實體標記(character entity),從而全部與文檔編碼一致(一般采用 UTF-8 編碼)。 ``` <head> <meta charset="UTF-8"> </head> ``` ### 引入 CSS 和 JavaScript 文件 根據 HTML5 規范,在引入 CSS 和 JavaScript 文件時一般不需要指定`type`屬性,因為`text/css`和`text/javascript`分別是它們的默認值。 #### HTML5 spec links * [Using link](http://www.w3.org/TR/2011/WD-html5-20110525/semantics.html#the-link-element) * [Using style](http://www.w3.org/TR/2011/WD-html5-20110525/semantics.html#the-style-element) * [Using script](http://www.w3.org/TR/2011/WD-html5-20110525/scripting-1.html#the-script-element) ~~~html <!-- External CSS --> <link rel="stylesheet" href="code-guide.css"> <!-- In-document CSS --> <style> /* ... */ </style> <!-- JavaScript --> <script src="code-guide.js"></script> ~~~ ### 實用為王 盡量遵循 HTML 標準和語義,但是不要以犧牲實用性為代價。任何時候都要盡量使用最少的標簽并保持最小的復雜度。 ### 屬性順序 HTML 屬性應當按照以下給出的順序依次排列,確保代碼的易讀性。 * `class` * `id`,`name` * `data-*` * `src`,`for`,`type`,`href`,`value` * `title`,`alt` * `role`,`aria-*` class 用于標識高度可復用組件,因此應該排在首位。id 用于標識具體組件,應當謹慎使用(例如,頁面內的書簽),因此排在第二位。 ~~~html <a class="..." id="..." data-toggle="modal" href="#"> Example link </a> <input class="form-control" type="text"> <img src="..." alt="..."> ~~~ ### 布爾(boolean)型屬性 布爾型屬性可以在聲明時不賦值。XHTML 規范要求為其賦值,但是 HTML5 規范不需要。 更多信息請參考[WhatWG section on boolean attributes](http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#boolean-attributes): > 元素的布爾型屬性如果有值,就是 true,如果沒有值,就是 false。 如果*一定*要為其賦值的話,請參考 WhatWG 規范: > 如果屬性存在,其值必須是空字符串或 \[...\] 屬性的規范名稱,并且不要在首尾添加空白符。 **簡單來說,就是不用賦值。** ~~~html <input type="text" disabled> <input type="checkbox" value="1" checked> <select> <option value="1" selected>1</option> </select> ~~~ ### 減少標簽的數量 編寫 HTML 代碼時,盡量避免多余的父元素。很多時候,這需要迭代和重構來實現。請看下面的案例: ~~~html <!-- Not so great --> <span class="avatar"> <img src="..."> </span> <!-- Better --> <img class="avatar" src="..."> ~~~ ### JavaScript 生成的標簽 通過 JavaScript 生成的標簽讓內容變得不易查找、編輯,并且降低性能。能避免時盡量避免。
                  <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>

                              哎呀哎呀视频在线观看