如何增加< a>的可点击区域标签按钮?
我从此帖子了解到,这些帖子始终使用< a>
标签或< button>
标签来制作按钮。现在,我尝试使用< a>
标记。我的问题是:有什么办法可以增加标签的可点击区域?假设我在div框中使用< a>
。我希望整个div框成为一个按钮。我可以将点击区域更改为整个div框吗?
感谢您的帮助。
I have learnt from this post that always use <a>
tags or <button>
tags to make button. Now I'm trying to use <a>
tag. My question is: is there any way to increase the tag clickable area? Say I'm using <a>
in a div box. I want the whole div box to become a button. Can I change the clicking area to the whole div box?
Thanks for you help.
编辑:
@ t1m0thy的答案比我的优雅,最好听从他的建议。
@t1m0thy's answer is more elegant than mine, better follow his advices.
此外, @aldemarcalazans 在评论中建议的漂亮链接: https://davidwalsh.name/html5-buttons 。
Also, nice link proposed by @aldemarcalazans in the comments: https://davidwalsh.name/html5-buttons.
原始答案:
使用< a />
,当您需要链接( anchor 的 a )时。需要按钮时使用<按钮/>
。
Use <a />
when you need a link (the a of anchor). Use <button />
when you need a button.
也就是说,如果您确实需要扩展< a />
,在其上添加CSS属性 display:block;
。然后,您可以指定宽度和/或高度(即好像它是< div />
)。
That said, if you really need to expand an <a />
, add the CSS attribute display: block;
on it. You'll then be able to specify a width and/or a height (i.e. as if it were a <div />
).