Is <div> inside <label> block correct?

HtmlCssTwitter Bootstrap

Html Problem Overview


I am using Bootstrap, it's demo of horizontal form:

<form class="form-horizontal" role="form">
  <div class="form-group">
    <label for="inputEmail1" class="col-lg-2 control-label">Email</label>
    <div class="col-lg-10">
      <input type="email" class="form-control" id="inputEmail1">
    </div>
  </div>
</form>

but I don't want create ID for each <input>, so

<form class="form-horizontal" role="form">
  <div class="form-group">
    <label class="block">
      <span class="col-lg-2 control-label">Email</span>
      <div class="col-lg-10">
        <input type="email" class="form-control">
      </div>
    </label>
  </div>
</form>

but display:block can't be inside display:inline, so I use CSS

.block {
  display: block;
}

it's working, but is it correct? because I heard that we should not put display:block element into display:inline element (label)

Html Solutions


Solution 1 - Html

No, HTML does not allow a <label> to contain a <div>.


See the specification for the label element:

> Content model: > Phrasing content, but with no descendant labelable elements unless it is the element's labeled control, and no descendant label elements.

Where phrasing content links to:

> Phrasing content is the text of the document, as well as elements that mark up that text at the intra-paragraph level. Runs of phrasing content form paragraphs. > > a abbr area (if it is a descendant of a map element) audio b bdi bdo br button canvas cite code data datalist del dfn em embed i iframe img input ins kbd keygen label map mark math meter noscript object output progress q ruby s samp script select small span strong sub sup svg textarea time u var video wbr text

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSteely WingView Question on Stackoverflow
Solution 1 - HtmlQuentinView Answer on Stackoverflow