Make a div into a link

后端 未结 27 2209
栀梦
栀梦 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条回答
  •  Happy的楠姐
    2020-11-22 04:14

    This post is Old I know but I just had to fix the same issue because simply writing a normal link tag with the display set to block does not make the whole div clickable in IE. so to fix this issue far simpler than having to use JQuery.

    Firstly let us understand why this happens: IE wont make an empty div clickable it only make the text/image within that div/a tag clickable.

    Solution: Fill the div with a bakground image and hide it from the viewer.

    How? You ask good questions, now listen up. add this backround style to the a tag

    > "background:url('some_small_image_path')
    > -2000px -2000px no-repeat;"
    

    And there you have it the whole div is now clickable. This was the best way for me cause Im using it for my Photo Gallery to let the user clik on one half of the image to move left/right and then place a small image as well just for visual effects. so for me I used the left and right images as background images anyway!

提交回复
热议问题