CSS 风格语法
Stylus 透明地支持常规的 CSS 风格语法。这意味着你不需要替代解析器,也不需要指定某个文件使用特定风格。
示例
下面是一个使用缩进方式的小样式:
stylus
border-radius()
-webkit-border-radius arguments
-moz-border-radius arguments
border-radius arguments
body a
font 12px/1.4 "Lucida Grande", Arial, sans-serif
background black
color #ccc
form input
padding 5px
border 1px solid
border-radius 5px
border-radius()
-webkit-border-radius arguments
-moz-border-radius arguments
border-radius arguments
body a
font 12px/1.4 "Lucida Grande", Arial, sans-serif
background black
color #ccc
form input
padding 5px
border 1px solid
border-radius 5px
由于大括号、冒号和分号是可选的,我们可以像普通 CSS 一样编写这个示例:
stylus
border-radius() {
-webkit-border-radius: arguments;
-moz-border-radius: arguments;
border-radius: arguments;
}
body a {
font: 12px/1.4 "Lucida Grande", Arial, sans-serif;
background: black;
color: #ccc;
}
form input {
padding: 5px;
border: 1px solid;
border-radius: 5px;
}
border-radius() {
-webkit-border-radius: arguments;
-moz-border-radius: arguments;
border-radius: arguments;
}
body a {
font: 12px/1.4 "Lucida Grande", Arial, sans-serif;
background: black;
color: #ccc;
}
form input {
padding: 5px;
border: 1px solid;
border-radius: 5px;
}
虽然 Stylus 不支持_每一种_可能的 CSS 类似语法,但它可以理解这样的代码:
stylus
border-radius() {
-webkit-border-radius: arguments;
-moz-border-radius: arguments;
border-radius: arguments;
}
body a
{
font: 12px/1.4 "Lucida Grande", Arial, sans-serif;
background: black;
color: #ccc;
}
form input {
padding: 5px;
border: 1px solid;
border-radius: 5px;
}
border-radius() {
-webkit-border-radius: arguments;
-moz-border-radius: arguments;
border-radius: arguments;
}
body a
{
font: 12px/1.4 "Lucida Grande", Arial, sans-serif;
background: black;
color: #ccc;
}
form input {
padding: 5px;
border: 1px solid;
border-radius: 5px;
}
由于我们可以混合和匹配这两种变体,下面的代码也是有效的:
stylus
border-radius()
-webkit-border-radius: arguments;
-moz-border-radius: arguments;
border-radius: arguments;
body a {
font: 12px/1.4 "Lucida Grande", Arial, sans-serif;
background: black;
color: #ccc;
}
form input
padding: 5px;
border: 1px solid;
border-radius: 5px;
border-radius()
-webkit-border-radius: arguments;
-moz-border-radius: arguments;
border-radius: arguments;
body a {
font: 12px/1.4 "Lucida Grande", Arial, sans-serif;
background: black;
color: #ccc;
}
form input
padding: 5px;
border: 1px solid;
border-radius: 5px;
变量、函数、混合器和 Stylus 提供的所有其他特性仍然像预期的那样工作:
stylus
main-color = white
main-hover-color = black
body a {
color: main-color;
&:hover { color: main-hover-color; }
}
body a { color: main-color; &:hover { color: main-hover-color; }}
main-color = white
main-hover-color = black
body a {
color: main-color;
&:hover { color: main-hover-color; }
}
body a { color: main-color; &:hover { color: main-hover-color; }}
这个规则有一些注意事项:由于两种风格可以混合和匹配,一些缩进规则仍然适用。所以尽管不是_每一个_普通的 CSS 样式表都能零修改地工作,但这个特性允许那些喜欢 CSS 语法的人继续使用,同时还能利用 Stylus 的其他强大特性。