Sort of Random Background Colors
I'm using nth-child selectors to
sort of
"randomize" background colors for adjacent elements. If you have a small known number of elements, you can just assign a color individually. But this is meant to get a random effect if you don't know how many elements you'll have, or you don't want to assign colors to a large known number of elements.
I think this could be cool for like a blog theme, dynamically populate navigation, or something. It's barely any code and only uses CSS. And you could "randomize" pretty much any property.
Scroll down for the math.
-
even
-
every third
-
every sixth
-
even
-
every fourth
-
every eighth
-
even
-
every third
-
every fourth
-
every sixth
Math
The mathematical intgeter sequence of the length of the pattern is the
Least Common Multiple where x is a Prime Number
. Because after 1, only the prime numbers will have the nth-child(odd) color.
Length of non-repeating patterns starting with 1 color
-
1
-
2
-
6
-
12
-
60
-
420
-
840
-
2,520
-
27,720
As you can see, it gets pretty random pretty fast. This example has 8 colors, so I could have 2,520 items without seeing the pattern repeat.
Other?
You could certainly repeat colors in the rule, which would allow adjacent colors, and longer unrepeating patterns with fewer colors. You lose the effect, though if you assign the same color to like even and fourth, or third and sixth.
List of 100 random words
From
List of Random Words
-
borne
-
montale
-
october
-
superresponsible
-
contendingly
-
mirliton
-
rubeniste
-
nonchurchgoer
-
manroot
-
underrecompense
-
eobiont
-
disbowelling
-
bucuresti
-
undecrepit
-
ordinate
-
platinocyanide
-
riffraff
-
uncasked
-
electroencephalography
-
plowshare
-
resuppress
-
allegan
-
stk
-
worshipless
-
chinese
-
antinationalist
-
rationalized
-
unsotted
-
omphale
-
duodenal
-
copilot
-
trainline
-
sunwards
-
crimelessness
-
podgier
-
nikolayev
-
pertussis
-
unrebated
-
apodictic
-
catlin
-
sell
-
tropospheric
-
nonremediability
-
mackerel
-
littb
-
deoxyribose
-
connivance
-
alif
-
genuineness
-
medianly
-
pyromania
-
liripoop
-
kissableness
-
haircut
-
superofficious
-
unepigrammatically
-
excursive
-
semeru
-
repetition
-
physicist
-
conductorial
-
higginsville
-
darts
-
galloglass
-
interpervading
-
assenter
-
wolver
-
copiously
-
nonexternality
-
symbolizing
-
hydroponic
-
disfiguring
-
oka
-
swig
-
nephritis
-
pseudorheumatic
-
ferrotungsten
-
boardroom
-
wensleydale
-
stepsister
-
topazolite
-
lighthearted
-
alk
-
alcoholometric
-
nonconsorting
-
cretin
-
hebridian
-
baalitical
-
trillium
-
courgette
-
councilman
-
overrestrain
-
gustable
-
nurture
-
unregaled
-
weatherability
-
theia
-
cornwallis
-
overillustrating
-
tarboosh
P.S. After I figured through this, I googled it and found that this isn't a new concept. But it was fun to come across it and figure it out on my own.