3
I was making a Menu that only appears when a checkbox
is checked. And to change the state of that checkbox
I need to click on label
of it, since the input:checkbox
is actually hidden.
What happens is that inside the label
I put a button
, and that way I can’t activate the checkbox
... Note that according to the documentation within the label
all the Phrasing_content
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label
About the: Phrasing Content
Note that I have here the codes, one that does not work with the button
inside, and another that works without the button
.
Then why the label
like the button
inside does not activate the checkbox
?
li{
display: inline-block;
background-color: red;
}
nav {
display: none;
}
[type="checkbox"] {
display: none;
}
[type="checkbox"]:checked + nav {
display: block;
}
label {
cursor:pointer;
}
<label for="btnx"><button>button</button></label>
<input type="checkbox" name="" id="btnx">
<nav>
<ul>
<li>item 01</li>
<li>item 02</li>
<li>item 03</li>
</ul>
</nav>
<br><br>
<label for="btny">label</label>
<input type="checkbox" name="" id="btny">
<nav>
<ul>
<li>item 04</li>
<li>item 05</li>
<li>item 06</li>
</ul>
</nav>
I believe it should be that way. Very complete the answer, [s]
– hugocsl
Cool, the technical explanation is exactly this. I went to read the documentation and there says that the
tabindex
transforms any element into "interactive content", but if you put a<span tabindex="1">foo</span>
inside the label and click on it, will activate the label. Will understand! rs...– Sam
@Sam, interactive I think just in the sense of entering the navigation list by keyboard, maybe for other purposes not. Where did you see this information?
– Woss
In this page: https://www.w3.org/TR/html5/dom.html#Interactive-content, in item 3.2.4.2.7
– Sam