美文网首页技术随笔CSS3
2022-06-22 随笔 巧妙使用 less 函数批量生成cl

2022-06-22 随笔 巧妙使用 less 函数批量生成cl

作者: narcissus灬 | 来源:发表于2022-06-22 11:13 被阅读0次

巧妙使用 less 函数批量生成class类

@base-size: 4; // 生成样式的基数
@max-size: 64; // 生成的最大值

// @class:  生成的class类名前缀
// @attribute:  使用的属性
.generate(@class, @attribute) {
  .loop(@n) when (@n <= @max-size) {
    .@{class}-@{n} {
      @{attribute}: 1px * @n !important;
    }
    .loop(@n + @base-size);
  }
  .loop(0)
}

.generate(m-t, margin-top);
.generate(m-b, margin-bottom);
.generate(m-l, margin-left);
.generate(m-r, margin-right);
.generate(p-t, padding-top);
.generate(p-b, padding-bottom);
.generate(p-l, padding-left);
.generate(p-r, padding-right);

生成对应的css

.m-t-0 {
  margin-top: 0px !important;
}
.m-t-4 {
  margin-top: 4px !important;
}
.m-t-8 {
  margin-top: 8px !important;
}
.m-t-12 {
  margin-top: 12px !important;
}
.m-t-16 {
  margin-top: 16px !important;
}
...
...

相关文章

  • 2022-06-22 随笔 巧妙使用 less 函数批量生成cl

    巧妙使用 less 函数批量生成class类 生成对应的css

  • Less的使用

    Less使用 1.什么是less 2.less有什么用 3.怎么使用less 4.less批量生成代码 less简...

  • Less 的Each用法

    Each函数是Less v3.7版本的新增用法,用于批量生成模板样式。文档如下: each Released ...

  • 遍历生成 padding margin ... 等类名

    一使用less 方法一 (生成指定) 方法二 调用: 使用scss 调用: 使用sass

  • WPS 批量图片生成PPT

    WPS 批量图片生成PPT 网页批量下载 使用chrome插件 image downloader 下载,默认根路径...

  • golang排序的Less接口

    golang中sort包中定义了排序需要的 Less 接口函数签名为 之前不是很明确Less函数该怎么写,使用的时...

  • Generator

    生成器函数(Generator Function) 生成器函数不能直接作为函数来使用 执行生成器函数会返回一个生成...

  • 五、less使用函数

    1、颜色函数 http://baike.renwuyi.com/2015-04/9042.html 2、计算宽高 ...

  • 使用less写函数

    惊艳不了谁的岁月,温暖不了谁的人生。 前端QQ群: 981668406在此附上我的QQ: 2489757828 有...

  • 将less文件转换成css文件

    两种方式,分别为:1、手动生成;2、使用webstorm自动生成。 手动生成 1、项目的文件结构 2、在less文...

网友评论

    本文标题:2022-06-22 随笔 巧妙使用 less 函数批量生成cl

    本文链接:https://www.haomeiwen.com/subject/duayvrtx.html