Entire div as a link?

后端 未结 8 1443
抹茶落季
抹茶落季 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:20

    No, div elements cannot have the href attribute, nor will they act like links. You can use the following in HTML5:

    However, not all current generation browsers (notably Firefox 3.6) supports this. The other alternative is to add a absolutely positioned a element that has 100% width and height to the div:

    div a {
        width: 100%;
        height: 100%;
        position: absolute;
        left: 0;
        top: 0;
    }
    

    This is valid HTML4, but it won't work on older versions of IE, of course. Otherwise should accomplish what you want. See: http://www.jsfiddle.net/uRh7j/

提交回复
热议问题