在 HTML 中正确嵌套表单标签

Proper nesting of form tags in HTML

我正在复制一个页面,想知道是否需要缩进 form 标签,如果它嵌套在 div 标签内。例如

      <div class="signup-form">
        <form method="post">
          <input type="text" value="First Name">
          <input type="text" value="Last Name">
        </form>

或者我写的时候不缩进。例如

      <div class="signup-form">
      <form method="post">
        <input type="text" value="First Name">
        <input type="text" value="Last Name">
      </form>

提前致谢。

HTML中的缩进无关紧要,这纯粹是为了便于阅读。

为了便于阅读,在您的示例中,我会缩进。

我会缩进,因为 form 标签包含在 div 标签中。

<div class="signup-form">
  <form method="post">
    <input type="text" value="First Name">
    <input type="text" value="Last Name">
  </form>
</div>

缩进不会影响标记的解释方式。您可以遵循可读性标准或您自己的风格偏好。

您还可以让 IDE 为您格式化代码...

Visual Studio: ctrl + k, ctrl + d

Sublime Text 3:只需select所有行ctrl + a然后从菜单select编辑→行→重新缩进