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.
Since clicking the label essentially clicks the checkbox, I would add padding or width to the label surrounding the checkbox so that it extends as far as you need your clickable area to be. Note that, for accessibility, I've added aria-label to the checkbox.
The <button> tag defines a clickable button. Inside a <button> element you can put text (and tags like <i> , <b> , <strong> , <br> , <img> , etc.). That is not possible with a button created with the <input> element!
To increase the area of a text link you can use the following css;
a { display: inline-block; position: relative; z-index: 1; padding: 2em; margin: -2em; }
Edit:
@t1m0thy's answer is more elegant than mine, better follow his advices.
Also, nice link proposed by @aldemarcalazans in the comments: https://davidwalsh.name/html5-buttons.
Original answer:
Use <a />
when you need a link (the a of anchor). Use <button />
when you need a button.
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 />
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With