How to disable a link using only CSS?

前端 未结 22 2928
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 02:58

Is there any way to disable a link using CSS?

I have a class called current-page and want links with this class to be disabled so that no action occurs

22条回答
  •  失恋的感觉
    2020-11-22 03:34

    One way you could do this with CSS, would be to set a CSS on a wrapping div that you set to disappear and something else takes it's place.

    E.g.:

    blah blah

    With a CSS like

    .disabled a.toggleLink { display: none; }
    span.toggleLink { display: none; }
    .disabled span.toggleLink { display: inline; }
    

    To actually turn off the a you'll have to replace it's click event or href, as described by others.

    PS: Just to clarify I'd consider this a fairly untidy solution, and for SEO it's not the best either, but I believe it's the best with purely CSS.

提交回复
热议问题