How to disable a link using only CSS?

前端 未结 22 2863
爱一瞬间的悲伤
爱一瞬间的悲伤 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:35

    It's possible to do it in CSS

    .disabled{
      cursor:default;
      pointer-events:none;
      text-decoration:none;
      color:black;
    }
    <a href="https://www.google.com" target="_blank" class="disabled">Google</a>

    See at:

    Please note that the text-decoration: none; and color: black; is not needed but it makes the link look more like plain text.

    0 讨论(0)
  • 2020-11-22 03:36

    You can also size another element so that it covers the links (using the right z-index): That will "eat" the clicks.

    (We discovered this by accident because we had an issue with suddenly inactive links due to "responsive" design causing a H2 to cover them when the browser window was mobile-sized.)

    0 讨论(0)
  • 2020-11-22 03:38

    Apply below class on html.

    .avoid-clicks {
      pointer-events: none;
    }
    
    0 讨论(0)
  • 2020-11-22 03:38

    pointer-events:none will disable the link:

    .disabled {
           pointer-events:none;
    }
    <a href="#" class="disabled">link</a>
    
    0 讨论(0)
  • 2020-11-22 03:40

    Bootstrap Disabled Link

    <a href="#" class="btn btn-primary btn-lg disabled" role="button">Primary link</a>
    
    <a href="#" class="btn btn-default btn-lg disabled" role="button">Link</a>
    

    Bootstrap Disabled Button but it looks like link

    <button type="button" class="btn btn-link">Link</button>
    
    0 讨论(0)
  • 2020-11-22 03:41

    Try this:

    <style>
    .btn-disable {
        display:inline-block;
        pointer-events: none;       
    }
    </style>
    
    0 讨论(0)
提交回复
热议问题