Make a div into a link

后端 未结 27 1681
栀梦
栀梦 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:14

    This is the best way to do it as used on the BBC website and the Guardian:

    I found the technique here: http://codepen.io/IschaGast/pen/Qjxpxo

    heres the html

    
    

    heres the CSS

    /**
     * Block Link
     *
     * A Faux block-level link. Used for when you need a block-level link with
     * clickable areas within it as directly nesting a tags breaks things.
     */
    
    
    .block-link {
        position: relative;
    }
    
    .block-link a {
      position: relative;
      z-index: 1;
    }
    
    .block-link .block-link__overlay-link {
        position: static;
        &:before {
          bottom: 0;
          content: "";
          left: 0;
          overflow: hidden;
          position: absolute;
          right: 0;
          top: 0;
          white-space: nowrap;
          z-index: 0;
        }
        &:hover,
        &:focus {
          &:before {
            background: rgba(255,255,0, .2);
          }
        }
    }
    

提交回复
热议问题