-1

This question was asked before, but with slightly different cases. In my case, I have body a:hover style defined and I want to disable it for some elements. According to a suggested answer to this question I have tried:

CSS:

body:not(.nohover a) a:hover {  
    color: #006699;
}

HTML:

<div class="nohover">
   <a href="mylink.html">My link text</a>
</div>

But it did not work. Does anyone know if it can be done with the :not pseudo-class? Or in a different way?

Edit: I think dippas was not wearing his reading glasses when marking this question as a duplicate; even stronger as an "exact duplicate". Fortunately, people like Edmund Reed tried to be helpful instead, and helped me answering my question.

4
  • 1
    have you add class nohover in your <a> element in which you want to disable? <a class="nohover">blah</a> Commented Apr 28, 2017 at 3:38
  • Yes. I have added it to my question above. Commented Apr 28, 2017 at 3:51
  • 1
    body:not(.nohover a) a:hover should be body a:not(.nohover):hover, and apply the class to the a itself, not a surrounding div. Commented Apr 28, 2017 at 3:59
  • @Edmund Reed: your answer proves to be working! Thanks a lot. Commented Apr 28, 2017 at 4:42

1 Answer 1

0

try this

body:not(.nohover)>a:hover {	
	color: #006699;
}
<body>
  <a>hover</a>
  <a>hover</a>     
  <div class="nohover">
    <a>no hover</a>
  </div>  
</body>

the css only applied if the structure is like body > a or will not work on structure body > .nohover > a. and this css also will not applied if the structure did not meet body > a, thus if you try to applied this css to element with structure body > element > a this css wont work

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.