codecamp

空格

以下几种情况不需要空格:

  • 属性名后
  • 多个规则的分隔符,
  • !important !
  • 属性值中'('后和')'前
  • 行末不要有多余的空格

以下几种情况需要空格:

  • 属性值前
  • 选择器>, +, ~前后
  • {
  • !important !
  • @else 前后
  • 属性值中的,
  • 注释/*后和*/

示例代码

/* not good */
.element {
    color :red! important;
    background-color: rgba(0,0,0,.5);
}


/* good */
.element {
    color: red !important;
    background-color: rgba(0, 0, 0, .5);
}


/* not good */
.element ,
.dialog{
    ...
}


/* good */
.element,
.dialog {


}


/* not good */
.element>.dialog{
    ...
}


/* good */
.element > .dialog{
    ...
}


/* not good */
.element{
    ...
}


/* good */
.element {
    ...
}


/* not good */
@if{
    ...
}@else{
    ...
}


/* good */
@if {
    ...
} @else {
    ...
}
分号
空行
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

编辑器配置和构建检查

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }