Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

244
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda