Is it possible to make an HTML anchor tag not clickable/linkable using CSS?

前端 未结 9 2160
故里飘歌
故里飘歌 2020-12-12 11:33

For example if I have this:

page link

Is there anything I can use for the style attribute that

相关标签:
9条回答
  • 2020-12-12 11:41

    It can be done in css and it is very simple. change the "a" to a "p". Your "page link" does not lead to somewhere anyway if you want to make it unclickable.

    When you tell your css to do a hover action on this specific "p" tell it this:

    (for this example I have given the "p" the "example" ID)

    #example
    {
      cursor:default;
    }
    

    Now your cursor will stay the same as it does all over the page.

    0 讨论(0)
  • 2020-12-12 11:47

    The answer is:

    <a href="page.html" onclick="return false">page link</a>
    
    0 讨论(0)
  • 2020-12-12 11:48

    CSS was designed to affect presentation, not behaviour.

    You could use some JavaScript.

    document.links[0].onclick = function(event) {
       event.preventDefault();
    };
    
    0 讨论(0)
  • 2020-12-12 11:53

    That isn't too easy to do with CSS, as it's not a behavioral language (ie JavaScript), the only easy way would be to use a JavaScript OnClick Event on your anchor and to return it as false, this is probably the shortest code you could use for that:

    <a href="page.html" onclick="return false">page link</a>
    
    0 讨论(0)
  • 2020-12-12 11:53
    <a href="page.html" onclick="return false" style="cursor:default;">page link</a>
    
    0 讨论(0)
  • 2020-12-12 11:55

    You can use this css:

    .inactiveLink {
       pointer-events: none;
       cursor: default;
    }
    

    And then assign the class to your html code:

    <a style="" href="page.html" class="inactiveLink">page link</a>
    

    It makes the link not clickeable and the cursor style an arrow, not a hand as the links have.

    or use this style in the html:

    <a style="pointer-events: none; cursor: default;" href="page.html">page link</a>
    

    but I suggest the first approach.

    0 讨论(0)
提交回复
热议问题