Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8557267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:32:13+00:00 2026-06-11T15:32:13+00:00

I have to style a table like structure that is to be designed using

  • 0

I have to style a table like structure that is to be designed using divs and spans.

  <div id="parentdiv">
         <div>
           <span>abc</span>
           <span>bcd</span>
           <span>cde</span>
         </div>
         <div>
           <span>123</span>
           <span>234</span>
           <span>456</span>
         </div>
         <div>
           <span>mno</span>
           <span>nop</span>
           <span>pqr</span>
         </div>
         <div>
           <span>678</span>
           <span>789</span>
           <span>890</span>
         </div>

here i have to style the alternate divs with 2 colors.
css i used was

        #parentdiv div :nth-of-type(2N)
         {
         background-color: #FFF;
         }

        #parentdiv div :nth-of-type(2N+1)
         {
          background-color: #f7f7f7;
         }

here, spans are getting styled.
please help me.
I want only divs to be styled so that alternate rows are colored accordigly.
I hope somebody will help me.
thanks 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:32:14+00:00Added an answer on June 11, 2026 at 3:32 pm

    Remove the space between div and nth-of-type like so:

        #parentdiv div:nth-of-type(2N)
         {
         background-color: #FFF;
         }
    
        #parentdiv div:nth-of-type(2N+1)
         {
          background-color: #f7f7f7;
         }
    

    This way it actually refers to the divs, rather than children of the divs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a structure that looks like this: <div class=project_group> <table> <tr style=display:none> <td>...</td>
In my web application, I have some divs and spans that make table like
I have a html page that contains a structure like this: <table class=pick> <tr>
I have a table structure like below: <table> <tr> <td> <div id=FirstDiv> <table> <tr>
I have divs structured like this: <div id='head'> <div class='graphData'> <table>...</table> </div> <div class='graph'>...</div>
We have a richfaces table (rich-table style class) and we would like to have
Consider I have a table, like below, that I am trying to populate with
Supposed We have the Html structure like below. <table class=main-tb> <tr> <td> </td> <td
I have a DOM structure like the following: <table class=playlist> <thead> <tr> <th>TH1</th> <th
I have a table structure like this <tr> <td> Text to move </td> </tr>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.