且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在SASS中将整数转换为十六进制

更新时间:2022-11-16 15:01:45

我会这样做:

$icons: "000", "001", "002";

@function icon($i) {
  @return "\F#{nth($icons, 1)}";
}

h1::before {
  content: icon(1);
}

如果要将单词与值相关联,请尝试使用列表列表并对其进行迭代.我不会假装这是非常有效的,但是可以.如果Sass有哈希值,那就太好了.

If you want to associate a word with a value, try using a list of lists and iterating through them. I'm not going to pretend this is very efficient, but it works. It would be nice if Sass had hashes.

$icons: '000' calendar, '001' inbox, '002' home

@function icon($call)
  @for $i from 1 through length($icons)
    @if $call == nth(nth($icons, $i), 2)
      @return "\F#{nth(nth($icons, $i), 1)}"

h1::before
  content: icon(calendar)