问题
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