I'm working on a project where I utilize SASS and Compass and need to somehow come up with some random numbers in the CSS file. Specifically, I need some floating point numbers between 0 and 1. Is this possible with SASS and Compass alone?
相关问题
- Adding a timeout to a render function in ReactJS
-
Why does the box-shadow property not apply to a
- Add animation to jQuery function Interval
- jQuery hover to slide?
- Issue with star rating css
Yes, as Scott said, it is possible, but I am not a Rails programmer, so I just wanted to copy and paste the code but first I did not know where to place the Code and then it did not work. I had to play around with the snipped and expanded it to more Flexibility that I had need for:
Ths can be used in a SCSS file like this:
and will printout:
I also did not know where to put the Code for this. I use SASS within compass framework. You can place this Code directly into your Compass Config.rb file.
Or you put it in another file and only put this line into your Compass Config.rb file:
This is very possible if you create a sass function since sass is ruby its as easy as opening the functions module and injecting your random function
require the file after sass has loaded
Then in your stylesheet
Update: With Sass 3.3 (2014), there is now a built-in
random()
function:http://sass-lang.com/documentation/Sass/Script/Functions.html#random-instance_method
You can also build your own simple seeded random function in Sass. Example (SCSS):
http://codepen.io/Sphinxxxx/pen/Gpmmye