Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda