永远遵循同一套编码规范 — 可以是这里列出的,也可以是你自己总结的。如果你发现本规范中有任何错误,敬请指正。通过 open an issue on GitHub 为本规范添加内容或贡献力量。
不管有多少人共同参与同一项目,一定要确保每一行代码都像是同一个人编写的。
</li>
或 </body>
)。
1 2 3 4 5 6 7 8 9 10 |
<span class="cp"><!DOCTYPE html></span> <span class="nt"><html></span> <span class="nt"><head></span> <span class="nt"><title></span>Page title<span class="nt"></title></span> <span class="nt"></head></span> <span class="nt"><body></span> <span class="nt"><img</span> <span class="na">src=</span><span class="s">"images/company-logo.png"</span> <span class="na">alt=</span><span class="s">"Company"</span><span class="nt">></span> <span class="nt"><h1</span> <span class="na">class=</span><span class="s">"hello-world"</span><span class="nt">></span>Hello, world!<span class="nt"></h1></span> <span class="nt"></body></span> <span class="nt"></html></span> |
为每个 HTML 页面的第一行添加标准模式(standard mode)的声明,这样能够确保在每个浏览器中拥有一致的展现。
1 2 3 4 5 |
<span class="cp"><!DOCTYPE html></span> <span class="nt"><html></span> <span class="nt"><head></span> <span class="nt"></head></span> <span class="nt"></html></span> |
根据 HTML5 规范:
强烈建议为 html 根元素指定 lang 属性,从而为文档设置正确的语言。这将有助于语音合成工具确定其所应该采用的发音,有助于翻译工具确定其翻译时所应遵守的规则等等。
更多关于 lang
属性的知识可以从 此规范 中了解。
这里列出了语言代码表。
1 2 3 |
<span class="nt"><html</span> <span class="na">lang=</span><span class="s">"en-us"</span><span class="nt">></span> <span class="c"><!-- ... --></span> <span class="nt"></html></span> |
IE 支持通过特定的 <meta>
标签来确定绘制当前页面所应该采用的 IE 版本。除非有强烈的特殊需求,否则最好是设置为 edge mode,从而通知 IE 采用其所支持的最新的模式。
阅读这篇 stack overflow 上的文章可以获得更多有用的信息。
1 |
<span class="nt"><meta</span> <span class="na">http-equiv=</span><span class="s">"X-UA-Compatible"</span> <span class="na">content=</span><span class="s">"IE=Edge"</span><span class="nt">></span> |
通过明确声明字符编码,能够确保浏览器快速并容易的判断页面内容的渲染方式。这样做的好处是,可以避免在 HTML 中使用字符实体标记(character entity),从而全部与文档编码一致(一般采用 UTF-8 编码)。
1 2 3 |
<span class="nt"><head></span> <span class="nt"><meta</span> <span class="na">charset=</span><span class="s">"UTF-8"</span><span class="nt">></span> <span class="nt"></head></span> |
根据 HTML5 规范,在引入 CSS 和 JavaScript 文件时一般不需要指定 type
属性,因为 text/css
和 text/javascript
分别是它们的默认值。
1 2 3 4 5 6 7 8 9 10 |
<span class="c"><!-- External CSS --></span> <span class="nt"><link</span> <span class="na">rel=</span><span class="s">"stylesheet"</span> <span class="na">href=</span><span class="s">"code-guide.css"</span><span class="nt">></span> <span class="c"><!-- In-document CSS --></span> <span class="nt"><style></span> <span class="c">/* ... */</span> <span class="nt"></style></span> <span class="c"><!-- JavaScript --></span> <span class="nt"><script </span><span class="na">src=</span><span class="s">"code-guide.js"</span><span class="nt">></script></span> |
尽量遵循 HTML 标准和语义,但是不要以牺牲实用性为代价。任何时候都要尽量使用最少的标签并保持最小的复杂度。
HTML 属性应当按照以下给出的顺序依次排列,确保代码的易读性。
class
id
, name
data-*
src
, for
, type
, href
, value
title
, alt
role
, aria-*
class 用于标识高度可复用组件,因此应该排在首位。id 用于标识具体组件,应当谨慎使用(例如,页面内的书签),因此排在第二位。
1 2 3 4 5 6 7 |
<span class="nt"><a</span> <span class="na">class=</span><span class="s">"..."</span> <span class="na">id=</span><span class="s">"..."</span> <span class="na">data-toggle=</span><span class="s">"modal"</span> <span class="na">href=</span><span class="s">"#"</span><span class="nt">></span> Example link <span class="nt"></a></span> <span class="nt"><input</span> <span class="na">class=</span><span class="s">"form-control"</span> <span class="na">type=</span><span class="s">"text"</span><span class="nt">></span> <span class="nt"><img</span> <span class="na">src=</span><span class="s">"..."</span> <span class="na">alt=</span><span class="s">"..."</span><span class="nt">></span> |
布尔型属性可以在声明时不赋值。XHTML 规范要求为其赋值,但是 HTML5 规范不需要。
更多信息请参考 WhatWG section on boolean attributes:
元素的布尔型属性如果有值,就是 true,如果没有值,就是 false。
如果一定要为其赋值的话,请参考 WhatWG 规范:
如果属性存在,其值必须是空字符串或 […] 属性的规范名称,并且不要在首尾添加空白符。
简单来说,就是不用赋值。
1 2 3 4 5 6 7 |
<span class="nt"><input</span> <span class="na">type=</span><span class="s">"text"</span> <span class="na">disabled</span><span class="nt">></span> <span class="nt"><input</span> <span class="na">type=</span><span class="s">"checkbox"</span> <span class="na">value=</span><span class="s">"1"</span> <span class="na">checked</span><span class="nt">></span> <span class="nt"><select></span> <span class="nt"><option</span> <span class="na">value=</span><span class="s">"1"</span> <span class="na">selected</span><span class="nt">></span>1<span class="nt"></option></span> <span class="nt"></select></span> |
编写 HTML 代码时,尽量避免多余的父元素。很多时候,这需要迭代和重构来实现。请看下面的案例:
1 2 3 4 5 6 7 |
<span class="c"><!-- Not so great --></span> <span class="nt"><span</span> <span class="na">class=</span><span class="s">"avatar"</span><span class="nt">></span> <span class="nt"><img</span> <span class="na">src=</span><span class="s">"..."</span><span class="nt">></span> <span class="nt"></span></span> <span class="c"><!-- Better --></span> <span class="nt"><img</span> <span class="na">class=</span><span class="s">"avatar"</span> <span class="na">src=</span><span class="s">"..."</span><span class="nt">></span> |
通过 JavaScript 生成的标签让内容变得不易查找、编辑,并且降低性能。能避免时尽量避免。
:
后应该插入一个空格。box-shadow
)。rgb()
、rgba()
、hsl()
、hsla()
或 rect()
值的内部的逗号后面插入空格。这样利于从多个属性值(既加逗号也加空格)中区分多个颜色值(只加逗号,不加空格)。.5
代替 0.5
;-.5px
代替 -0.5px
)。#fff
。在扫描文档时,小写字符易于分辨,因为他们的形式更易于区分。#fff
代替 #ffffff
。input[type="text"]
。只有在某些情况下是可选的,但是,为了代码的一致性,建议都加上双引号。margin: 0;
代替 margin: 0px;
。对于这里用到的术语有疑问吗?请参考 Wikipedia 上的 syntax section of the Cascading Style Sheets article。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<span class="c">/* Bad CSS */</span> <span class="nc">.selector</span><span class="o">,</span> <span class="nc">.selector-secondary</span><span class="o">,</span> <span class="nc">.selector</span><span class="o">[</span><span class="nt">type</span><span class="o">=</span><span class="nt">text</span><span class="o">]</span> <span class="p">{</span> <span class="nl">padding</span><span class="p">:</span><span class="m">15px</span><span class="p">;</span> <span class="nl">margin</span><span class="p">:</span><span class="m">0px</span> <span class="m">0px</span> <span class="m">15px</span><span class="p">;</span> <span class="nl">background-color</span><span class="p">:</span><span class="n">rgba</span><span class="p">(</span><span class="m">0</span><span class="p">,</span> <span class="m">0</span><span class="p">,</span> <span class="m">0</span><span class="p">,</span> <span class="m">0.5</span><span class="p">);</span> <span class="nl">box-shadow</span><span class="p">:</span><span class="m">0px</span> <span class="m">1px</span> <span class="m">2px</span> <span class="m">#CCC</span><span class="p">,</span><span class="nb">inset</span> <span class="m">0</span> <span class="m">1px</span> <span class="m">0</span> <span class="m">#FFFFFF</span> <span class="p">}</span> <span class="c">/* Good CSS */</span> <span class="nc">.selector</span><span class="o">,</span> <span class="nc">.selector-secondary</span><span class="o">,</span> <span class="nc">.selector</span><span class="o">[</span><span class="nt">type</span><span class="o">=</span><span class="s1">"text"</span><span class="o">]</span> <span class="p">{</span> <span class="nl">padding</span><span class="p">:</span> <span class="m">15px</span><span class="p">;</span> <span class="nl">margin-bottom</span><span class="p">:</span> <span class="m">15px</span><span class="p">;</span> <span class="nl">background-color</span><span class="p">:</span> <span class="n">rgba</span><span class="p">(</span><span class="m">0</span><span class="p">,</span><span class="m">0</span><span class="p">,</span><span class="m">0</span><span class="p">,</span><span class="m">.5</span><span class="p">);</span> <span class="nl">box-shadow</span><span class="p">:</span> <span class="m">0</span> <span class="m">1px</span> <span class="m">2px</span> <span class="m">#ccc</span><span class="p">,</span> <span class="nb">inset</span> <span class="m">0</span> <span class="m">1px</span> <span class="m">0</span> <span class="m">#fff</span><span class="p">;</span> <span class="p">}</span> |
相关的属性声明应当归为一组,并按照下面的顺序排列:
由于定位(positioning)可以从正常的文档流中移除元素,并且还能覆盖盒模型(box model)相关的样式,因此排在首位。盒模型排在第二位,因为它决定了组件的尺寸和位置。
其他属性只是影响组件的内部(inside)或者是不影响前两组属性,因此排在后面。
完整的属性列表及其排列顺序请参考 Recess。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<span class="nc">.declaration-order</span> <span class="p">{</span> <span class="c">/* Positioning */</span> <span class="nl">position</span><span class="p">:</span> <span class="nb">absolute</span><span class="p">;</span> <span class="nl">top</span><span class="p">:</span> <span class="m">0</span><span class="p">;</span> <span class="nl">right</span><span class="p">:</span> <span class="m">0</span><span class="p">;</span> <span class="nl">bottom</span><span class="p">:</span> <span class="m">0</span><span class="p">;</span> <span class="nl">left</span><span class="p">:</span> <span class="m">0</span><span class="p">;</span> <span class="nl">z-index</span><span class="p">:</span> <span class="m">100</span><span class="p">;</span> <span class="c">/* Box-model */</span> <span class="nl">display</span><span class="p">:</span> <span class="nb">block</span><span class="p">;</span> <span class="nl">float</span><span class="p">:</span> <span class="nb">right</span><span class="p">;</span> <span class="nl">width</span><span class="p">:</span> <span class="m">100px</span><span class="p">;</span> <span class="nl">height</span><span class="p">:</span> <span class="m">100px</span><span class="p">;</span> <span class="c">/* Typography */</span> <span class="nl">font</span><span class="p">:</span> <span class="nb">normal</span> <span class="m">13px</span> <span class="s1">"Helvetica Neue"</span><span class="p">,</span> <span class="nb">sans-serif</span><span class="p">;</span> <span class="nl">line-height</span><span class="p">:</span> <span class="m">1.5</span><span class="p">;</span> <span class="nl">color</span><span class="p">:</span> <span class="m">#333</span><span class="p">;</span> <span class="nl">text-align</span><span class="p">:</span> <span class="nb">center</span><span class="p">;</span> <span class="c">/* Visual */</span> <span class="nl">background-color</span><span class="p">:</span> <span class="m">#f5f5f5</span><span class="p">;</span> <span class="nl">border</span><span class="p">:</span> <span class="m">1px</span> <span class="nb">solid</span> <span class="m">#e5e5e5</span><span class="p">;</span> <span class="nl">border-radius</span><span class="p">:</span> <span class="m">3px</span><span class="p">;</span> <span class="c">/* Misc */</span> <span class="nl">opacity</span><span class="p">:</span> <span class="m">1</span><span class="p">;</span> <span class="p">}</span> |
@import
与 <link>
标签相比,@import
指令要慢很多,不光增加了额外的请求次数,还会导致不可预料的问题。替代办法有以下几种:
<link>
元素请参考 Steve Souders 的文章了解更多知识。
1 2 3 4 5 6 7 |
<span class="c"><!-- Use link elements --></span> <span class="nt"><link</span> <span class="na">rel=</span><span class="s">"stylesheet"</span> <span class="na">href=</span><span class="s">"core.css"</span><span class="nt">></span> <span class="c"><!-- Avoid @imports --></span> <span class="nt"><style></span> <span class="k">@import</span> <span class="sx">url("more.css")</span><span class="p">;</span> <span class="nt"></style></span> |
将媒体查询放在尽可能相关规则的附近。不要将他们打包放在一个单一样式文件中或者放在文档底部。如果你把他们分开了,将来只会被大家遗忘。下面给出一个典型的实例。
1 2 3 4 5 6 7 8 9 |
<span class="nc">.element</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="nc">.element-avatar</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="nc">.element-selected</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="k">@media</span> <span class="p">(</span><span class="n">min-width</span><span class="p">:</span> <span class="m">480px</span><span class="p">)</span> <span class="p">{</span> <span class="nc">.element</span> <span class="p">{</span> <span class="err">...</span><span class="p">}</span> <span class="nc">.element-avatar</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="nc">.element-selected</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="p">}</span> |
当使用特定厂商的带有前缀的属性时,通过缩进的方式,让每个属性的值在垂直方向对齐,这样便于多行编辑。
在 Textmate 中,使用 Text → Edit Each Line in Selection (⌃⌘A)。在 Sublime Text 2 中,使用 Selection → Add Previous Line (⌃⇧↑) 和 Selection → Add Next Line(⌃⇧↓)。
1 2 3 4 5 |
<span class="c">/* Prefixed properties */</span> <span class="nc">.selector</span> <span class="p">{</span> <span class="nl">-webkit-box-shadow</span><span class="p">:</span> <span class="m">0</span> <span class="m">1px</span> <span class="m">2px</span> <span class="n">rgba</span><span class="p">(</span><span class="m">0</span><span class="p">,</span><span class="m">0</span><span class="p">,</span><span class="m">0</span><span class="p">,</span><span class="m">.15</span><span class="p">);</span> <span class="nl">box-shadow</span><span class="p">:</span> <span class="m">0</span> <span class="m">1px</span> <span class="m">2px</span> <span class="n">rgba</span><span class="p">(</span><span class="m">0</span><span class="p">,</span><span class="m">0</span><span class="p">,</span><span class="m">0</span><span class="p">,</span><span class="m">.15</span><span class="p">);</span> <span class="p">}</span> |
对于只包含一条声明的样式,为了易读性和便于快速编辑,建议将语句放在同一行。对于带有多条声明的样式,还是应当将声明分为多行。
这样做的关键因素是为了错误检测 — 例如,CSS 校验器指出在 183 行有语法错误。如果是单行单条声明,你就不会忽略这个错误;如果是单行多条声明的话,你就要仔细分析避免漏掉错误了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<span class="c">/* Single declarations on one line */</span> <span class="nc">.span1</span> <span class="p">{</span> <span class="nl">width</span><span class="p">:</span> <span class="m">60px</span><span class="p">;</span> <span class="p">}</span> <span class="nc">.span2</span> <span class="p">{</span> <span class="nl">width</span><span class="p">:</span> <span class="m">140px</span><span class="p">;</span> <span class="p">}</span> <span class="nc">.span3</span> <span class="p">{</span> <span class="nl">width</span><span class="p">:</span> <span class="m">220px</span><span class="p">;</span> <span class="p">}</span> <span class="c">/* Multiple declarations, one per line */</span> <span class="nc">.sprite</span> <span class="p">{</span> <span class="nl">display</span><span class="p">:</span> <span class="n">inline-block</span><span class="p">;</span> <span class="nl">width</span><span class="p">:</span> <span class="m">16px</span><span class="p">;</span> <span class="nl">height</span><span class="p">:</span> <span class="m">15px</span><span class="p">;</span> <span class="nl">background-image</span><span class="p">:</span> <span class="sx">url(../img/sprite.png)</span><span class="p">;</span> <span class="p">}</span> <span class="nc">.icon</span> <span class="p">{</span> <span class="nl">background-position</span><span class="p">:</span> <span class="m">0</span> <span class="m">0</span><span class="p">;</span> <span class="p">}</span> <span class="nc">.icon-home</span> <span class="p">{</span> <span class="nl">background-position</span><span class="p">:</span> <span class="m">0</span> <span class="m">-20px</span><span class="p">;</span> <span class="p">}</span> <span class="nc">.icon-account</span> <span class="p">{</span> <span class="nl">background-position</span><span class="p">:</span> <span class="m">0</span> <span class="m">-40px</span><span class="p">;</span> <span class="p">}</span> |
在需要显示地设置所有值的情况下,应当尽量限制使用简写形式的属性声明。常见的滥用简写属性声明的情况如下:
padding
margin
font
background
border
border-radius
大部分情况下,我们不需要为简写形式的属性声明指定所有值。例如,HTML 的 heading 元素只需要设置上、下边距(margin)的值,因此,在必要的时候,只需覆盖这两个值就可以。过度使用简写形式的属性声明会导致代码混乱,并且会对属性值带来不必要的覆盖从而引起意外的副作用。
在 MDN(Mozilla Developer Network)上一篇非常好的关于shorthand properties 的文章,对于不太熟悉简写属性声明及其行为的用户很有用。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<span class="c">/* Bad example */</span> <span class="nc">.element</span> <span class="p">{</span> <span class="nl">margin</span><span class="p">:</span> <span class="m">0</span> <span class="m">0</span> <span class="m">10px</span><span class="p">;</span> <span class="nl">background</span><span class="p">:</span> <span class="no">red</span><span class="p">;</span> <span class="nl">background</span><span class="p">:</span> <span class="sx">url("image.jpg")</span><span class="p">;</span> <span class="nl">border-radius</span><span class="p">:</span> <span class="m">3px</span> <span class="m">3px</span> <span class="m">0</span> <span class="m">0</span><span class="p">;</span> <span class="p">}</span> <span class="c">/* Good example */</span> <span class="nc">.element</span> <span class="p">{</span> <span class="nl">margin-bottom</span><span class="p">:</span> <span class="m">10px</span><span class="p">;</span> <span class="nl">background-color</span><span class="p">:</span> <span class="no">red</span><span class="p">;</span> <span class="nl">background-image</span><span class="p">:</span> <span class="sx">url("image.jpg")</span><span class="p">;</span> <span class="nl">border-top-left-radius</span><span class="p">:</span> <span class="m">3px</span><span class="p">;</span> <span class="nl">border-top-right-radius</span><span class="p">:</span> <span class="m">3px</span><span class="p">;</span> <span class="p">}</span> |
避免不必要的嵌套。这是因为虽然你可以使用嵌套,但是并不意味着应该使用嵌套。只有在必须将样式限制在父元素内(也就是后代选择器),并且存在多个需要嵌套的元素时才使用嵌套。
扩展阅读:
1 2 3 4 5 6 7 8 9 |
<span class="c1">// Without nesting </span><span class="nc">.table</span> <span class="o">></span> <span class="nt">thead</span> <span class="o">></span> <span class="nt">tr</span> <span class="o">></span> <span class="nt">th</span> <span class="p">{</span> <span class="err">…</span> <span class="p">}</span> <span class="nc">.table</span> <span class="o">></span> <span class="nt">thead</span> <span class="o">></span> <span class="nt">tr</span> <span class="o">></span> <span class="nt">td</span> <span class="p">{</span> <span class="err">…</span> <span class="p">}</span> <span class="c1">// With nesting </span><span class="nc">.table</span> <span class="o">></span> <span class="nt">thead</span> <span class="o">></span> <span class="nt">tr</span> <span class="p">{</span> <span class="o">></span> <span class="nt">th</span> <span class="p">{</span> <span class="err">…</span> <span class="p">}</span> <span class="o">></span> <span class="nt">td</span> <span class="p">{</span> <span class="err">…</span> <span class="p">}</span> <span class="p">}</span> |
为了提高可读性,在圆括号中的数学计算表达式的数值、变量和操作符之间均添加一个空格。
1 2 3 4 5 6 7 8 9 |
<span class="c1">// Bad example </span><span class="nc">.element</span> <span class="p">{</span> <span class="nl">margin</span><span class="p">:</span> <span class="m">10px</span> <span class="m">0</span> <span class="o">@</span><span class="n">variable</span><span class="o">*</span><span class="m">2</span> <span class="m">10px</span><span class="p">;</span> <span class="p">}</span> <span class="c1">// Good example </span><span class="nc">.element</span> <span class="p">{</span> <span class="nl">margin</span><span class="p">:</span> <span class="m">10px</span> <span class="nf">0</span> <span class="p">(</span><span class="o">@</span><span class="n">variable</span> <span class="o">*</span> <span class="m">2</span><span class="p">)</span> <span class="m">10px</span><span class="p">;</span> <span class="p">}</span> |
代码是由人编写并维护的。请确保你的代码能够自描述、注释良好并且易于他人理解。好的代码注释能够传达上下文关系和代码目的。不要简单地重申组件或 class 名称。
对于较长的注释,务必书写完整的句子;对于一般性注解,可以书写简洁的短语。
1 2 3 4 5 6 7 8 9 10 11 |
<span class="c">/* Bad example */</span> <span class="c">/* Modal header */</span> <span class="nc">.modal-header</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="c">/* Good example */</span> <span class="c">/* Wrapping element for .modal-title and .modal-close */</span> <span class="nc">.modal-header</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> |
.btn
和 .btn-danger
)。.btn
代表 button,但是 .s
不能表达任何意思。.js-*
class 来标识行为(与样式相对),并且不要将这些 class 包含到 CSS 文件中。在为 Sass 和 Less 变量命名时也可以参考上面列出的各项规范。
1 2 3 4 5 6 7 8 9 |
<span class="c">/* Bad example */</span> <span class="nc">.t</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="nc">.red</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="nc">.header</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="c">/* Good example */</span> <span class="nc">.tweet</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="nc">.important</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="nc">.tweet-header</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> |
[class^="..."]
)。浏览器的性能会受到这些因素的影响。扩展阅读:
1 2 3 4 5 6 7 8 9 |
<span class="c">/* Bad example */</span> <span class="nt">span</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="nc">.page-container</span> <span class="nf">#stream</span> <span class="nc">.stream-item</span> <span class="nc">.tweet</span> <span class="nc">.tweet-header</span> <span class="nc">.username</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="nc">.avatar</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="c">/* Good example */</span> <span class="nc">.avatar</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="nc">.tweet-header</span> <span class="nc">.username</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="nc">.tweet</span> <span class="nc">.avatar</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<span class="c">/* * Component section heading */</span> <span class="nc">.element</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="c">/* * Component section heading * * Sometimes you need to include optional context for the entire component. Do that up here if it's important enough. */</span> <span class="nc">.element</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> <span class="c">/* Contextual sub-component or modifer */</span> <span class="nc">.element-heading</span> <span class="p">{</span> <span class="err">...</span> <span class="p">}</span> |
将你的编辑器按照下面的配置进行设置,以避免常见的代码不一致和差异:
参照文档并将这些配置信息添加到项目的 .editorconfig
文件中。例如:Bootstrap 中的 .editorconfig 实例。更多信息请参考 about EditorConfig。