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

Removing a property from a css element

I want to remove a property from an element, when the user hovers an other element:

<button id="element1" type="button">Element1</button>
<button id="element2" type="button">Element2</button>
<style>
#element1:hover{
 __here I want to remove a property from element2__
}
</style>

>Solution :

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

There are two parts to your problem.

Selecting the other element

If you want to involve two different elements in your selector (which you need to in order to have both the element you are targeting as well as the element with the pseudo-class :hover) then you need to use a combinator.

The specifics will depend on the relationship between the two elements, and often there is no suitable relationship you can use.

In this case, you can use the adjacent sibling combinator.

#element1:hover + #element2 { ... }

Removing a property

There are a variety of values you could give to the property to give various effects of removal. They have subtle differences so you should compare them in the documentation to determine which suits your needs.

Make sure you check the browser compatibility tables. revert-layer in particular is very new with limited support.

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