Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I need to select the first non-hidden/visible child element excluding records with a specific class only using css

In the below example, I want to change the text color of the first child that is visible.

Here <div> with the class of HideWidget should be excluded; so, I want to see "two," "four" and "eight" to be colored red.

I have tried below css and its showing only "four":

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

.parent .child .field:not(.HideWidget):first-child {
  color: red;
}
<div class='parent'>
  <div class='child'>
    <div class='field HideWidget'>One</div>
    <div class='field'>Two</div>
    <div class='field'>Three</div>
  </div>
  <div class='child'>
    <div class='field'>Four</div>
    <div class='field'>Five</div>
    <div class='field'>Six</div>
  </div>
  <div class='child'>
    <div class='field HideWidget'>Seven</div>
    <div class='field'>Eight</div>
    <div class='field'>Nine</div>
  </div>

JSFiddle

>Solution :

`

.parent .child .field:not(.HideWidget):first-child,
.parent .child .field.HideWidget+.field {
    color: red;
}
<div class='parent'>
  <div class='child'>
    <div class='field HideWidget'>One</div>
    <div class='field'>Two</div>
    <div class='field'>Three</div>
  </div>
  <div class='child'>
    <div class='field'>Four</div>
    <div class='field'>Five</div>
    <div class='field'>Six</div>
  </div>
  <div class='child'>
    <div class='field HideWidget'>Seven</div>
    <div class='field'>Eight</div>
    <div class='field'>Nine</div>
  </div>

Should help you with red color on Two, Four and Eight

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading