...">

Why does someone want to wrap form elements inside <div> tags?

For instance. here is a simple form (which I often use):

<form class="login">
      <input class="login_username" type="text" value="username"/>
      <input class="login_password" type="text" value="password"/>
      <input type="submit" value="Login"/>
</form>

But I read several books and often see some of my friends:

<form class="login">
   <div class="login_username">
      <input class="login_input" type="text" value="username"/>
   </div>
   <div class="login_password">
      <input class="login_password" type="text" value="password"/>
   </div>
      <input type="submit" value="Login"/>
</form>

The difference is that they often wrap all the components inside the div tag and then assign its class name (although there is only one component inside the div tag). I do not know what are the advantages when they do it.

Thank:)

+4
source share
3 answers

CSS JavaScripts. . , , , , .

4.10.1.1

form, . input, . , label; label. p. , :

<form>
  <p><label>Customer name: <input></label></p>
</form>

: - W3C:

+6

, .

, , , CSS Javascript.

.

, , , , input > s .

+3

This will mainly be for CSS styles and potentially use some of the classes for Javascript hooks.

+1
source

All Articles