Problems calling a SASS built-in function [duplicate]

这一生的挚爱 提交于 2020-01-05 12:07:32

问题


I have this fragment of SASS code:

@font-face {
  $rndnum: random(1000);
  font-family: myfont;
  src:url('fonts/myfont#{$rndnum}.svg')
  font-weight: bold;
  font-style: normal;
}

I need to put a random number after the name of the font, I know it seems stupid operation, but I need it. However the problem is that I get the following result:

@font-face {
  font-family: myfont;
  src:url('fonts/myfontrandom(1000).svg') /* <== HERE */
  font-weight: bold;
  font-style: normal;
}

The function does not get called for some reason... Where am I doing wrong?

Something more...

I tried calling another function like percentage:

@font-face {
  $rndnum: percentage(0.2);
  ...

And it worked in that case... looks like it is not recognizing random as a valid function...


回答1:


Have you tried just concatenating the string?

src:url('fonts/myfont'+$rndnum+'.svg');

And do you have the code for what $rndnum is being set as since this could also be a problem with how that variable is set.

Edit 1:

Your code works for me. Do you just need the semi-colon after the src line?

What version of sass are you using?

I tried it here and it seemed to work perfectly fine on Sass version 3.3.3 but not on version 3.2.15 (the two versions offered on that site).



来源:https://stackoverflow.com/questions/22538430/problems-calling-a-sass-built-in-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!