Entire div as a link?

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

    <a href="#"><div></div></a>
    

    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/

    0 讨论(0)
  • 2021-02-04 05:22

    I do not think this is possible without the use of onclick event.You can use display:block; for displaying the link as a div but nothing else.

    0 讨论(0)
提交回复
热议问题