- 参考
- airbnb
- 补充
- 使用变量命名常用的数字和颜色
- css calc 尽可能不使用 flex 在大部分下可以满足需求
- 兼容性的-webkit 不需要手写..有 postcss 的插件帮你处理:如: -webkit-transition
- z-index 无必要不要超过 100, 最好不要超时 10, 一般 1, 9 都够用
- 避免使用!important
- https://github.com/amfe/article/issues/47)">避免给 width, height, top, left等添加animate,使用transform(https://github.com/amfe/article/issues/47)
- 除非使用rgba(),否则使用十六进制颜色代码#000
- 避免使用内联样式
参考
Google:https://google.github.io/styleguide/htmlcssguide.html
airbnb:https://github.com/airbnb/css
airbnb
建议使用行注释 (//) 代替块注释。
建议注释独占一行。避免行末注释。
在定义无边框样式时,使用 0 代替 none。
尽可能使用简写的属性书写方式。
/* 不推荐 */border-top-style: none;font-family: palatino, georgia, serif;font-size: 100%;line-height: 1.6;padding-bottom: 2em;padding-left: 1em;padding-right: 1em;padding-top: 0/* 推荐 */border-top: 0;font: 100%/1.6 palatino, georgia, serif;padding: 0 1em 2em;
省略 “0” 后的单位。
flex: 0px; /* This flex-basis component requires a unit. */flex: 1 1 0px; /* Not ambiguous without the unit, but needed in IE11. */margin: 0;padding: 0;
省略前导 “0” 值。
font-size: .8em;
在可能的情况下使用3个字符的十六进制表示法。
/* 不推荐 */color: #eebbcc;/* 推荐 */color: #ebc;
用连字符分隔 id 和 class 名中的单词。
/* 不推荐: 单词未分开 */.demoimage {}/* 不推荐:使用下划线而不是连字符 */.error_status {}/* 推荐 */#video-id {}.ads-sample {}
缩进块内容。
@media screen, projection {html {background: #fff;color: #444;}}
每个属性后使用分号结束。
/* 推荐 */.test {display: block;height: 100px;}
属性名称的冒号后有一个空格。
/* 推荐 */h3 {font-weight: bold;}
在选择器和后面的声明块之间使用一个空格。
/* 推荐 */#video {margin-top: 1em;}
每个选择器和声明独立成行。
/* 推荐 */h1,h2,h3 {font-weight: normal;line-height: 1.2;}
使用新空行分离规则。
html {background: #fff;}body {margin: auto;width: 50%;}
补充
使用变量命名常用的数字和颜色
color: var(--primary-color)
css calc 尽可能不使用 flex 在大部分下可以满足需求
//badwidth: calc(100% - 200px);//goodflex: 1;
兼容性的-webkit 不需要手写..有 postcss 的插件帮你处理:如: -webkit-transition
z-index 无必要不要超过 100, 最好不要超时 10, 一般 1, 9 都够用
避免使用!important
//badcolor: red!important;
避免给 width, height, top, left等添加animate,使用transform(https://github.com/amfe/article/issues/47)
除非使用rgba(),否则使用十六进制颜色代码#000
避免使用内联样式
//bad<div style={{color: ...fontSize: ...}}> ...</div>
