Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Bootstrap 5 表单


堆叠表单

所有带类 .form-control 的文本 <input> 和   <textarea> 元素将获得适当的表单样式

示例

<form action="/action_page.php">
  <div class="mb-3 mt-3">
    <label for="email" class="form-label">电子邮件:</label>
    <input type="email" class="form-control" id="email" placeholder="输入电子邮件" name="email">
  </div>
  <div class="mb-3">
    <label for="pwd" class="form-label">密码:</label>
    <input type="password" class="form-control" id="pwd" placeholder="输入密码" name="pswd">
  </div>
  <div class="form-check mb-3">
    <label class="form-check-label">
      <input class="form-check-input" type="checkbox" name="remember"> 记住我
    </label>
  </div>
  <button type="submit" class="btn btn-primary">提交</button>
</form>
自己尝试 »

还要注意,我们为每个标签元素添加了 .form-label 类,以确保正确的填充。

复选框的标记不同。它们被包裹在一个带有 .form-check 的容器元素中,标签有一个 .form-check-label 类,而复选框和单选按钮使用 .form-check-input


文本域

示例

<label for="comment">评论:</label>
<textarea class="form-control" rows="5" id="comment" name="text"></textarea>
自己尝试 »


表单行/网格(内联表单)

如果你想让表单元素并排显示,请使用 .row.col

示例

<form>
  <div class="row">
    <div class="col">
      <input type="text" class="form-control" placeholder="输入电子邮件" name="email">
    </div>
    <div class="col">
      <input type="password" class="form-control" placeholder="输入密码" name="pswd">
    </div>
  </div>
</form>
自己尝试 »

你将在 Bootstrap 网格章节 中学习更多关于列和行的知识。


表单控件大小

你可以使用 .form-control-lg.form-control-sm 更改 .form-control 输入的大小

示例

<input type="text" class="form-control form-control-lg" placeholder="大型输入">
<input type="text" class="form-control" placeholder="普通输入">
<input type="text" class="form-control form-control-sm" placeholder="小型输入">
自己尝试 »

禁用和只读

使用 disabled 和/或 readonly 属性来禁用输入字段

示例

<input type="text" class="form-control" placeholder="普通输入">
<input type="text" class="form-control" placeholder="禁用输入" disabled>
<input type="text" class="form-control" placeholder="只读输入" readonly>
自己尝试 »

纯文本输入

使用 .form-control-plaintext 类来设置没有边框的输入字段的样式,但保留适当的边距和填充

示例

<input type="text" class="form-control-plaintext" placeholder="纯文本输入">
<input type="text" class="form-control" placeholder="普通输入">
自己尝试 »

颜色选择器

要正确设置类型为“color”的输入的样式,请使用 .form-control-color

示例

<input type="color" class="form-control form-control-color" value="#CCCCCC">
自己尝试 »

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.