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

Trying to hide pseudo element on input focus through ~

I’m trying to hide parents pseudo element ::before hide on input focus. Currently it looks like this

.parent::before{
  content: 'default';
}

.parent:focus-within::before{
  display: none;
}
<div class="parent">
  <input type="text">
  <button>awd</button>
</div>

and it doesn’t seem to work. I don’t want to involve any js/jquery. Would be great if there any vanila css or atleast scss solution.
Thanks in advance!


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

>Solution :

You can use :focus-within on .parent

The :focus-within pseudo-class matches elements that either themselves match :focus or that have descendants which match :focus.

.parent:focus-within::before {
  display :none
}

Working code below: I have modified the content to show it works perfectly, click on the Input to check

.parent::before{
  content: 'psuedo conetent';
}


.parent:focus-within::before {
  display :none
}
<div class="parent">
  HTML
  <input type="text">
</div>
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