Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
How to use CSS :nth-child(odd) using Angular component for table rows?

Disclaimer: I am new to Angular.

I have a very simple Angular app that creates a table of items, say "products".

I have a component called "Products" and a sub-component (if that is the terminology) called product-item.

All is working fine save for the styling I want.

In the "Products" component, I have the following HTML:

<table>
<tbody>
<ng-container *ngFor="let product of productList">
<app-product-item [product]="product "></app-product-item>
</ng-container>   
</tbody>
</table>

In the product-item I have:

<tr>
  <td>{{product.Num}}</td>
  <td>{{product.Name}}</td>
</tr>

Now I would like to apply the following style:

tr:nth-child(odd) {background-color: #d46969;}

When I do so in the product-item.component.css file, all rows have the styling, not only the even rows. Can someone explain what I am doing wrong?

Thank you.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Do a ng-deep on app-product-item and that will help you access the inner html

In css

app-product-item:nth-child(odd) ::ng-deep tr{
 // add your styles
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!