开发者

Link div to external url

开发者 https://www.devze.com 2023-03-29 17:33 出处:网络
I want my div to be clickable and link to an external url. Why doesn\'t this work or what should I do instead?

I want my div to be clickable and link to an external url. Why doesn't this work or what should I do instead?

html:

 <div id="logo_left">
   <a href="..external url.."></a>
 </div>

Stylesheet:开发者_开发技巧

#logo_left {
  //stylestuff
}
#logo_left a {
  display: block;
  height: 100%;
  width:  100%;
}


You should take only the <a> and make it into a display: block;

a.block { display: block; height: 100px; width: 100px; }

Working Example


Alternatively, if you are using <!doctype html>, you could wrap the div inside an <a> and have it clickable that way.

Working Example


  You need to add an event on the on click property of div

 <

div id="logo_left" onclick="window.redirect=..external url..">
     </div>


You don't need JavaScript to link to a specific URL just use the complete address starting from http:

<div id="logo_left">
   <a href="http://www.external-url.com"></a>
</div>
0

精彩评论

暂无评论...
验证码 换一张
取 消