How does css take the last specified element?

there are many li,li arranged in 3 rows. Now you need to control the style of the last li (li:last-child). If the last li is 1-3, read style a, and if it is 4-6, read style b. Cycle on 7: 9, read a, 5, 10, 12, read b. How to get pure css?

Css
Jan.12,2022

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        li:last-child:nth-of-type(6n+1),li:last-child:nth-of-type(6n+2),li:last-child:nth-of-type(6n+3){
            color: red;
        }
        li:last-child:nth-of-type(6n+4),li:last-child:nth-of-type(6n+5),li:last-child:nth-of-type(6n){
            color: yellow;
        }
    </style>
</head>
<body>
<ul>

</ul>
<script>
    var ul=document.querySelector('ul');
    var index=1;
    setInterval(function(){
        ul.insertAdjacentHTML('beforeend',`<li>${indexPP}</li>`)
    },500);
</script>
</body>
</html>

try this

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-1e5986d-45547.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-1e5986d-45547.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?