Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is <div> inside <label> block correct?

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)

like image 560
Steely Wing Avatar asked Sep 04 '13 09:09

Steely Wing


People also ask

What is meaning of div in label?

The <div> tag defines a division or a section in an HTML document. The <div> tag is used as a container for HTML elements - which is then styled with CSS or manipulated with JavaScript. The <div> tag is easily styled by using the class or id attribute. Any sort of content can be put inside the <div> tag!

Can we write div inside form?

It is totally fine . The form will submit only its input type controls ( *also Textarea , Select , etc...). You have nothing to worry about a div within a form .

How do I label a div in HTML?

<input type="time"> <input type="url">

Can a div be inside a paragraph?

The <div> tag can NOT be inside <p> tag, because the paragraph will be broken at the point, where the <div> tag is entered. To apply styles inside a paragraph use <span> tag, which is used with inline elements.


1 Answers

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

like image 56
Quentin Avatar answered Oct 08 '22 17:10

Quentin