+ 2
If can do " random color " in HTML ??? And how ???
5 Answers
+ 19
What format are your colors?
You could use JS to change their colors upon execution...
Like:
/*#RRGGBB accepts 3 2-digit hex params, max = 255 (ff) for each 2-digit*/
var rnd = Math.floor(Math.random() * Math.pow(255, 3)); //255*255*255
var col = '#' + rnd.toString(16); //convert to HEX
element.style.color = col; //CSS
+ 8
please, explain the question, may I can help you.
+ 6
you need a JS to do it.
I'll show an example:
HTML:
<div id="test"></div>
JS:
function random() {
r = Math.ceil(Math.random() * 255); // this will make a rendom number
g = Math.ceil(Math.random() * 255); // this also same
b = Math.ceil(Math.random() * 255); // this also same
test = document.querySelector("#test"); // select element with id "test"
test.style.background = "rgb("+r+","+g+","+b+")"; // add the random number into rgb() code
}
window.onload = random; // run the function after html is loaded
+ 1
I want to create a lot of objects and each of them has a random color
0
Thanks