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

(CSS) How to use :not and :hover at the same time?

I want to stop showing hover while checkbox is checked, how can I do?

// Typescript
<label className={styles.checkbox_container}>
  <input type="checkbox" />This is a Label
  <span className={styles.checkmark}></span> // customized tick symbol with red color for checked status
  <span className={styles.checkmarkHover}></span> // customized tick symbol with blue color for :hover;
</label>  

// CSS 
.checkbox_container:not(.checkbox_container input:checked):hover input ~ .checkmarkHover {
    // does not work
}

When the checkbox is not being checked, hover works.
When the checkbox is being checked, hover expected to do nothing.

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’re applying :not to the wrong element. .checkbox_container will never match .checkbox_container input:checked anyway. You want input:not(:checked).

.checkbox_container:hover input:not(:checked) ~ .checkmarkHover
{
    color: #f00;
}
<label class="checkbox_container">
  <input type="checkbox" />This is a Label
  <span class="checkmark">XXX</span>
  <span class="checkmarkHover">YYY</span>
</label>  
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