Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have an <input> and <label> with different parent elements?

Tags:

html

css

For example:

<input type="checkbox" id="nav-toggle" />

<nav>
    Nav stuff
</nav>

<main>
   <label for="nav-toggle">Menu</label>
</main>

For use in an a css only menu panel like this: http://codepen.io/jimahyland/pen/mAVGmj

It seems to work fine, but is there anything fundamentally wrong with this approach?

like image 326
Jim Hyland Avatar asked Sep 10 '25 13:09

Jim Hyland


1 Answers

Yes, input and label can have different parents.

Most standard block-level elements, such as body, div, article, section and aside, accept flow content, which includes input and label.

As long as the parent accepts flow content or phrasing content, input and label can exist as a child element.

like image 97
Michael Benjamin Avatar answered Sep 13 '25 03:09

Michael Benjamin