13

Since my last question was marked as a duplicate, while it was no duplicate, and no-one is changing it back, I will just ask my question again.

I have an <a>, which has, by default, a on-click function. This <a> also has a hover, which I would like to keep.

How do I disable the click function, but keep the hover?

P.s., I would love to see a CSS solution!

Important! Last time, my question was marked as a duplicate of this question: How to disable a link using only CSS?, but pointer-events:none; is also blocking the hover.

If it is still a duplicate, please mark it as a duplicate of a question that is truly a duplicate.


Edit: I forgot to mention, that my hover is made like this: https://jsfiddle.net/7o3dbak7/7/

HTML:

<div class="container">
  <ul>
    <li id="item1"><a href="somelinkthatistherebecauseitis">hoverable object</a></li>
    <li id="item2">text object, here comes alot of text explaining certain features of the website.</li>
  </ul>
</div>

CSS:

.container ul #item2 {
  display: none;
  width: 150px;
  padding: 20px;
  background: red;
  color: white;
  cursor: pointer
}

.container ul #item1 {
  pointer-events: none;
}

.container ul #item1:hover + #item2 {
  display: block;
}
Maarten Wolfsen
  • 1,625
  • 3
  • 19
  • 35
  • Sorry, I voted to close your previous question as I misunderstood what you were asking. In future, rather than asking a new question, simply edit your question to clarify your intent (and explain why you feel it isn't a duplicate). – James Donnelly Oct 21 '16 at 10:46
  • So do you really need to use an anchor element there? Anyway James answer is still valid: https://jsfiddle.net/7o3dbak7/1/ – A. Wolff Oct 21 '16 at 10:48
  • So you want something like a tooltip, you can put the text of #item2 id inside #item1 in a
    tag and you can show it on hover of #item1 id. Why are you creating multiple
  • tags.
– Guru Oct 21 '16 at 10:54
  • 1
    Does this answer your question? [Is there a \`pointer-events:hoverOnly\` or similar in CSS?](https://stackoverflow.com/questions/22168420/is-there-a-pointer-eventshoveronly-or-similar-in-css) – Gajus Mar 05 '20 at 22:39