Make a div into a link

后端 未结 27 2373
栀梦
栀梦 2020-11-22 03:15

I have a

block with some fancy visual content that I don\'t want to change. I want to make it a clickable link.

I\'m looking for something l

27条回答
  •  我在风中等你
    2020-11-22 04:15

    This worked for me:

    HTML:

    WHATEVER YOU WANT

    CSS:

    .span-link {
      position:absolute;
      width:100%;
      height:100%;
      top:0;
      left: 0;
      z-index: 9999;
    }
    

    This adds an invisible element (the span), which covers your entire div, and is above your whole div on the z-index, so when someone clicks on that div, the click is essentially intercepted by your invisible "span" layer, which is linked.

    Note: If you're already using z-indexes for other elements, just make sure the value of this z-index is higher than anything you want it to rest "on top" of.

提交回复
热议问题