Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random properties pure CSS

I'm just wondering, is it possible to have randomly generated properties using only CSS, or will some javascript be required.

The effect I want to achieve is to have the coloured divs randomly positioned on the page.

http://jsfiddle.net/pphheerroonn/F95Ju/2/embedded/result/

HTML:
<div class="box wsbg1"></div>
<div class="box wsbg2"></div>
<div class="box wsbg3"></div>
<div class="box wsbg4"></div>


CSS:
body {
    height: 600px; background-color: #66ccff;}
.box {
    height: 200px; width: 200px; 
    -webkit-transform: rotate(-5deg);
    -moz-transform: rotate(-5deg);
    -webkit-box-shadow: 15px 15px 20px rgba(0, 0, 0, 0.3);
    -moz-box-shadow: 15px 15px 20px rgba(0, 0, 0, 0.3);
}
.wsbg1 {background-color: #ec0689;}
.wsbg2 {background-color: #ffde00;}
.wsbg3 {background-color: #09aeee;}
.wsbg4 {background-color: #5eb345;}
​
like image 404
Paul Herron Avatar asked May 20 '26 21:05

Paul Herron


2 Answers

No, CSS is deterministic. Either create randomness with javascript, or serve up a randomly generated css file each time with PHP.

like image 149
Eric Avatar answered May 22 '26 10:05

Eric


You could do that with CSS pre processors such as LESS or SASS, here is a relevant answer for the same:

Possible to create random numbers in SASS / Compass?

like image 38
JAR.JAR.beans Avatar answered May 22 '26 10:05

JAR.JAR.beans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!