+ 2

If can do " random color " in HTML ??? And how ???

22nd May 2018, 3:21 PM
Oleg Shevchuk
Oleg Shevchuk - avatar
5 Respuestas
+ 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
22nd May 2018, 4:03 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 8
please, explain the question, may I can help you.
22nd May 2018, 3:41 PM
Amethyst Animion
Amethyst Animion - avatar
+ 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
22nd May 2018, 4:03 PM
Amethyst Animion
Amethyst Animion - avatar
+ 1
I want to create a lot of objects and each of them has a random color
22nd May 2018, 3:48 PM
Oleg Shevchuk
Oleg Shevchuk - avatar
0
Thanks
22nd May 2018, 4:07 PM
Oleg Shevchuk
Oleg Shevchuk - avatar