How can I style even and odd elements

0 votes

Is it feasible to choose even and odd list item instances using CSS pseudo-classes?

The following should result in a list of items in alternate colours, but all I get is a list of blue things:

<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>
Jul 29 in CSS by Edureka
• 9,940 points
14 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In CSS

0 votes
1 answer

How can I use CSS to style multiple images differently?

You can do that in HTML (delete ...READ MORE

answered Jun 21 in CSS by Edureka
• 9,540 points
26 views
0 votes
0 answers

How can I create a round arrow with only HTML and CSS?

Using CSS and HTML, I'm attempting to ...READ MORE

Jul 8 in CSS by Edureka
• 9,940 points
11 views
0 votes
1 answer

How can I position my div at the bottom of its container?

Bottom and position properties can be used ...READ MORE

answered Jun 10 in CSS by Edureka
• 9,540 points
30 views
0 votes
1 answer
0 votes
1 answer

How can I define colors as variables in CSS?

CSS does not use variables. You can, ...READ MORE

answered Jun 21 in CSS by Edureka
• 9,540 points
19 views
0 votes
0 answers

How can I vertically center a div element for all browsers using CSS?

I want to center a div vertically with CSS. ...READ MORE

Jun 22 in CSS by Edureka
• 9,940 points
19 views
0 votes
1 answer

jQuery vs document.querySelectorAll

As seen above, querySelector() methodcan only be used ...READ MORE

answered Jun 14 in JQuery by gaurav
• 17,580 points
67 views
0 votes
0 answers

Combinators in CSS

everyone! I am quite new to HTML ...READ MORE

Jul 8 in CSS by Edureka
• 9,940 points
11 views
0 votes
2 answers

Define a SQL query? What is the difference between SELECT and UPDATE Query? How do you use SQL in SAS?

HI.. SQL is Structured Query Language, which is ...READ MORE

answered Aug 8, 2020 in PHP by anonymous
4,749 views
0 votes
1 answer

Using/Handling colon inside a JSF generated HTML element ID in CSS selector

Yes, you can.  Just Backslash (\) the colon.  Like ...READ MORE

answered Nov 14, 2018 in Others by DataKing99
• 8,240 points
1,703 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP