Created
July 9, 2014 02:46
-
-
Save juanbrujo/7e4e17428dc8881d0e7e to your computer and use it in GitHub Desktop.
Mixin to generate random color in LESS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.randomColor(){ | |
@randomColor: `Math.floor(Math.random()*16777215).toString(16)`; | |
@colorHex: e(@randomColor); | |
@color: ~"#@{colorHex}"; | |
} | |
// USE | |
body { | |
.randomColor(); | |
background-color: @color; | |
} |
This always gives a color:
spin(#F0F, @i*@colorsneeded)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sometimes the code snippet generates an invalid hex code (with 5 number/letters) Use this instead to fix the issue:
I found the answer in the comment section of this post:
https://css-tricks.com/snippets/javascript/random-hex-color/