开发者

Setting image to anchor tag not working

开发者 https://www.devze.com 2023-04-06 20:03 出处:网络
I want to set image to anchor tag but it is not working. Can anybody tell me what is wrong? <a href=\"#\" style=\"width:200px;height:100px;background:url(\'@Url.Content(\"~/Content/Images/facebook

I want to set image to anchor tag but it is not working. Can anybody tell me what is wrong?

<a href="#" style="width:200px;height:100px;background:url('@Url.Content("~/Content/Images/facebook.png")');"></a>

Note: Don't pay attention to background. It is Asp.Net MVC syntax. But rest assured the image is loaded correctly. Can anybody tell me what am I doing wrong? If I type something in anchor tag it works fine. But I don't want to type anything开发者_如何学Go.


You need to either set the display property to block or inline-block for the link

<a href="#" style="display:block; width:200px;height:100px; ...

Links are inline by default.


Because a link is an inline element, it can't have width and height.

Set this attribute on it:

display: inline-block;
0

精彩评论

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

关注公众号