LESS使用记录

本文介绍了Less预处理器中的循环函数`.Loop()`及其在CSS样式中的应用,通过实例展示了如何遍历颜色数组来设置背景色。同时,文章还探讨了Less的计算函数,如将像素值转换为rem单位,用于响应式设计。通过对这些核心概念的解析,读者可以更好地理解Less在前端开发中的强大功能。
摘要由CSDN通过智能技术生成

Less 循环

@colorArr: #37a2da, #92b5e9, #f7c0e3;
@len: length(@colorArr);

.Loop(@index) when(@index <= @len) {
  li:nth-child(@{index}) {
    background-color: extract(@colorArr, @index);
  }
  .Loop(@index+1)
}

.Loop(1);

输出为:

li:nth-child(1) {
  background-color: #37a2da;
}
li:nth-child(2) {
  background-color: #92b5e9;
}
li:nth-child(3) {
  background-color: #f7c0e3;
}

Less 函数

计算形参@px / 40

.convert(@px) {
  @var: unit(@px * pow(40, -1));
  @rem: ~'@{var}rem';
}

//使用
margin: 0 .convert(27px)[@rem];

输出为:

margin: 0 0.675rem;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值