空格
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 {
...
}
以上内容是否对您有帮助:
← 分号
更多建议: