I have a label
with "for="the pointer to the checkbox input"
" and as long as I know, this for
can be added only for label
. Therefore, I need to add inside of the label
a <button>
(I need it), but the click event isn't working properly - it doesn't check the checkbox the for
is pointing to.
What are the possibilities I can use here if I must place <button>
inside the label
, with only html+css coding?
some code for example:
<input type="checkbox" id="thecheckbox" name="thecheckbox"> <div for="thecheckbox"><button type="button">Click Me</button></div>
The a element may be wrapped around entire paragraphs, lists, tables, and so forth, even entire sections, so long as there is no interactive content within (e.g. buttons or other links). In other words, you can nest any elements inside an <a> except the following: <a> <audio> (if the controls attribute is present)
You can create it using a <label> element. You will need to bind the label to the input element by setting the for attribute on the label to the same value as the id attribute on the input element.
Yes, your button must have so form of text label associated with it.
No, you can't put anything inside an input tag. You can put an input tag inside a label, and the label will be automatically associated with that input. That means when you click on the label, it focusses the input.
It turns out you can make a <button>
operate an input, but only if you put the <label>
inside the <button>
.
<button type="button"> <label for="my-checkbox">Button go outside the label</label> </button> <input type="checkbox" id="my-checkbox">
Although this contravenes the W3C specs:
The interactive element label must not appear as a descendant of the button element. https://www.w3.org/TR/html-markup/label.html
You can use transparent pseudo element that overlays the checkbox and the button itself that will catch mouse events.
Here's an example:
html:
<label> <input type="checkbox"> <button class="disable">button</button> </label>
css:
.disable{pointer-events:fill} label{position:relative} label:after{ position: absolute; content: ""; width: 100%; height: 100%; background: transparent; top:0; left:0; right:0; bottom:0; }
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