空格

2025-08-06 11:59 更新

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

  • 属性名后
  • 多个规则的分隔符,
  • !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下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号