So far most of the solutions, including the solution by OP, will stop having list markers with more than 5 elements in the list, which is a show-stopper for me.
The ideal solution in my mind, would be to make the next color at a given percentage of previous color. But that requires programming, as far as I know. Another solution to make the list marker keep appearing is to extend the nth-of-type
-selector using formulas, see css-tricks.com :nth-of-type.
This explains how you can write :nth-of-type(an+b)
, where a
represent the repeat factor, n
is literal, +
(or -
) indicates addition/subtraction, and b
is offset. In other words, if you use 5n+1
it denotes the 1st, 6th, 11th, ... elements, and 5n+2
denotes the 2nd, 7th, 8th, ... elements.
In the code below, based on RoToRa's answer, I've only changed the :nth-of-type(...)
selectors into :nth-of-type(5n+x)
(with x
varying from 1 through 5. This repeats the formatting for every 5th element.
ul.animated-list {
list-style-type: none;
width: 250px;
border: 2px solid #a9a9a9;
border-radius: 16px;
margin: 0 auto;
}
ul.animated-list > li {
margin: 10px 0;
}
ul.animated-list > li::before {
content: "";
display: inline-block;
width: 20px;
height: 20px;
margin-right: 20px;
border-radius: 0 50%;
transform: rotate(0deg);
transition: transform 0.1s;
}
ul.animated-list > li:hover::before {
transform: rotate(-45deg);
}
ul.animated-list > li:nth-of-type(5n+1)::before {
background-color: rgba(30, 30, 30, 1.0);
}
ul.animated-list > li:nth-of-type(5n+2)::before {
background-color: rgba(60, 60, 60, 1.0);
}
ul.animated-list > li:nth-of-type(5n+3)::before {
background-color: rgba(90, 90, 90, 1.0);
}
ul.animated-list > li:nth-of-type(5n+4)::before {
background-color: rgba(120, 120, 120, 1.0);
}
ul.animated-list > li:nth-of-type(5n+5)::before {
background-color: rgba(150, 150, 150, 1.0);
}
<ul class="animated-list">
<li>Alpha</li>
<li>Beta</li>
<li>Gamma</li>
<li>Delta</li>
<li>Epsilon</li>
<li>Zeta</li>
<li>Eta</li>
<li>Theta</li>
<li>Iota</li>
<li>Kappa</li>
<li>Lambda</li>
</ul>
If modifiying to include the opacity suggested by Gabor, one can use the concept of a base color, and with some slight justification to the base rotation, and implementation of the down-and-up scheme, one gets the following snippet:
ul.animated-list {
list-style-type: none;
width: 250px;
border: 2px solid #a9a9a9;
border-radius: 16px;
margin: 0 auto;
}
ul.animated-list > li {
margin: 10px 0;
}
ul.animated-list > li::before {
content: "";
display: inline-block;
width: 15px;
height: 10px;
margin-right: 20px;
border-radius: 0 50%;
transform: rotate(-15deg);
transition: transform 0.1s;
background-color: rgb(51, 166, 214); # Base color
}
ul.animated-list > li:hover::before {
transform: rotate(-60deg);
}
/* Not needed when doing opacity on background.color
ul.animated-list > li:nth-of-type(8n+1)::before {
background-color: rgba(30, 30, 30, 1.0);
} */
ul.animated-list > li:nth-of-type(8n+2)::before {
opacity: 0.8;
}
ul.animated-list > li:nth-of-type(8n+3)::before {
opacity: 0.6;
}
ul.animated-list > li:nth-of-type(8n+4)::before {
opacity: 0.4;
}
ul.animated-list > li:nth-of-type(8n+5)::before {
opacity: 0.2;
}
ul.animated-list > li:nth-of-type(8n+6)::before {
opacity: 0.4;
}
ul.animated-list > li:nth-of-type(8n+7)::before {
opacity: 0.6;
}
ul.animated-list > li:nth-of-type(8n+8)::before {
opacity: 0.8;
}
<ul class="animated-list">
<li>Alpha</li>
<li>Beta</li>
<li>Gamma</li>
<li>Delta</li>
<li>Epsilon</li>
<li>Zeta</li>
<li>Eta</li>
<li>Theta</li>
<li>Iota</li>
<li>Kappa</li>
<li>Lambda</li>
</ul>