Is it possible to use CSS pseudo-classes to select even and odd instances of list items?

I’d expect the following to produce a list of alternating colors, but instead I get a list of blue items:

<html>
    <head>
        <style>
            li { color: blue }
            li:odd { color:green }
            li:even { color:red }
        </style>
    </head>
    <body>
        <ul>
            <li>ho</li>
            <li>ho</li>
            <li>ho</li>
            <li>ho</li>
            <li>ho</li>
        </ul>
    </body>
</html>

9 Answers
9

Leave a Reply

Your email address will not be published. Required fields are marked *