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

185
Views
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 answers
Answer question

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 Report

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 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!