Entire div as a link?

后端 未结 8 1454
抹茶落季
抹茶落季 2021-02-04 04:55

I want to use an entire div as a link.. without the use of \"onclick\"

Is this possible with a simple href?

Thanks

8条回答
  •  甜味超标
    2021-02-04 05:00

    You can accomplish this by creating a small transparent PNG (say, 10px * 10px) and using CSS to set the width and height of the PNG to 100%. Then you can wrap the img tag with your a href tag.

    Here's the HTML:

    Here's the CSS:

    #YourHeader img {
        width: 100%;
        height: 100%; 
    }
    

    This is especially handy if #YourHeader is an empty div whose only purpose is to display a header image via its background-image attribute.

提交回复
热议问题