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
)
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!
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 .
<input type="time"> <input type="url">
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.
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
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