How to set a different color for each li tag

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div class="logo">
        <ul>
            <li>123123</li>
            <li>2312312</li>
            <li>sjfsdf</li>
            <li>sdfsdaf</li>
            <li>sdfagag</li>
            <li>sdfafsf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
            <li>sdafafasdf</li>
        </ul>
    </div>
</body>
</html>

Total 4 colors
the first li is red
the second li is blue
the third li is black
the fourth li is yellow

5-8li repeat the above colors, and so on
can pure css be achieved? Is there a better way to write


can be realized. Learn about the css selector nth-child (4N)


.
ul:li:nth-child(4n+1){
    color: red;
}
ul:li:nth-child(4n+2){
    color: blue;
}
ul:li:nth-child(4n+3){
    color: black;
}
ul:li:nth-child(4n){
    color: yellow;
}
I hope I can help you. Welcome to my official account of Wechat: Front-end Guide
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea9c77-1f80.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea9c77-1f80.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?