CSS Stylus(一)

CMD命令 stylus -w hello.styl -o hello.css
语法
  • 选择器
// 缩排
.hello
    width 100px
    height 100px
    background yellow

//规则集
textarea, input
    background #eeeeee

//父级引用
.user
    background lightgreen
    &:hover
        background limegreen


box-shadow()
-webkit-box-shadow arguments
-moz-box-shadow arguments
box-shadow arguments
html.ie8 &,
html.ie7 &,
html.ie6 &,
  border 2px solid arguments[length(arguments) - 1]

body
    #login
        box-shadow 1px 1px 3px #eee

//消除歧义
pad(n)
    padding (- n)

body
    pad(5px)
  • 变量
//变量
$font-size = 16px
$font = $font-size Arial, sans-serif
body
    font $font

//属性查找(会逐级冒泡查找)
#logo
    position absolute
    top 50%
    left 50%
    width 150px
    height 150px
    margin-left -(@width/2)
    margin-top -(@height/2)

//属性查找(动态定义)
position()
    position arguments
    z-index 1 unless @z-index

#logo
    position absolute
  • 插值
prefix(name, args)
    -webkit-{name} args
    -moz-{name} args
    {name} args

border-radius()
    prefix('border-radius', arguments)

button
    border-radius 1px 2px

table
    for row in 1 2 3 4 5
        tr:nth-child({row})
            height 10px * row
  • 输出结果
/************选择器**************/
.hello {
  width: 100px;
  height: 100px;
  background: #ff0;
}
textarea,
input {
  background: #eee;
}
.user {
  background: #90ee90;
}
.user:hover {
  background: #32cd32;
}
-webkit-box-shadow arguments #login,
-moz-box-shadow arguments #login,
box-shadow arguments #login,
html.ie8 #login,
html.ie7 #login,
html.ie6 #login,
border 2px solid arguments[length(arguments) - 1] #login,
body #login {
  box-shadow: 1px 1px 3px #eee;
}
body {
  padding: -5px;
}
/************变量**************/
body {
  font: 16px Arial, sans-serif;
}
#logo {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 150px;
  height: 150px;
  margin-left: -75px;
  margin-top: -75px;
}
#logo {
  position: absolute;
  z-index: 1;
}
/************插值**************/
button {
  -webkit-border-radius: 1px 2px;
  -moz-border-radius: 1px 2px;
  border-radius: 1px 2px;
}
table tr:nth-child(1) {
  height: 10px;
}
table tr:nth-child(2) {
  height: 20px;
}
table tr:nth-child(3) {
  height: 30px;
}
table tr:nth-child(4) {
  height: 40px;
}
table tr:nth-child(5) {
  height: 50px;
}
Stylus是一种CSS预处理器,它可以让你用更简洁、更强大的语法来编写CSS代码。与Sass和Less类似,Stylus可以通过编译将你的代码转换成普通的CSS文件。相比于直接编写CSS,使用Stylus可以提供更多的功能,例如使用变量、函数等。 如果你想学习Stylus,你可以参考一些资源。Stylus官方中文文档提供了详细的教程和参考资料,可以让你更好地了解Stylus的语法和用法。另外,张鑫旭的网站也提供了一个Stylus文档,其中包含了一些实例和示例代码。 在Stylus中,你可以使用混合器来重复使用一些样式代码。混合器允许你定义一组样式规则,然后将其应用到不同的选择器上。下面是一个典型的混合器应用例子,使用border-radius来生成不同浏览器前缀的border-radius属性。 ``` border-radius(n) -webkit-border-radius n -moz-border-radius n border-radius n div border-raduis(10px) ``` 经过编译后,以上代码将生成以下CSS代码: ``` div { -webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius: 10px; } ``` 这个例子展示了如何使用混合器来简化重复的样式代码,以及如何在Stylus中定义和使用函数。如果你想了解更多关于Stylus的用法和技巧,可以参考上述提到的资源。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [【styluscss预处理器stylus的安装以及简单用法](https://blog.csdn.net/meichaoWen/article/details/109309698)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [CSS预处理框架——Stylus](https://blog.csdn.net/cainiaoyihao_/article/details/115719282)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [css 预编译处理器 - Stylus](https://blog.csdn.net/ZXW_Future/article/details/106207209)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值