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

193
Visualizações
Removing <div> with specific value

I have an issue with removing the class

<div>
  <div class="categoryname current-category">Category block</div>
  <div class="categoryname">Category block</div>
</div>

I am trying to display only block with class "categoryname current-category"

I try this CSS code:

.categoryname{
    display:none;
}
.categoryname:first-child{
    display:block;
}

But that CSS code every time display first category, I am looking to only display block with "current-category" class, Some pages have a situation that class "current-category" is on other block:

<div>
  <div class="categoryname">Category block</div>
  <div class="categoryname current-category">Category block</div>
</div>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

When styling an element that contains more than one class you need to write the classnames without spaces

.categoryname{
  display: none;
}
.categoryname.current-category{
  display: block;
}
<div>
  <div class="categoryname current-category">Category block</div>
  <div class="categoryname">Category block</div>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

The issue is related to the CSS Specificity.

Specificity is by which browsers decide which CSS property values are the most relevant to an element and, therefore, will be applied. - MDN

In your case, due to using pseudo-class, the specificity of the second CSS increases which will always apply by overriding the first CSS that you have written.

<element class="categoryname">: Selector Specificity: (0, 1, 0)

<element class="categoryname" :first-child>: Selector Specificity: (0, 2, 0)

So to fix your problem:

 .categoryname {
   display: none;
 }

 .categoryname .current-category {
   display: block; //Specificity: (0, 2, 0)
 }

For more details on the concept visit the official MDN Document: https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity

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