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 输入组


输入组

.input-group 类是一个容器,通过在输入字段前面或后面添加图标、文本或按钮作为“帮助文本”来增强输入。

要设置指定帮助文本的样式,请使用 .input-group-text

@
@example.com

示例

<form>
  <div class="input-group">
    <span class="input-group-text">@</span>
    <input type="text" class="form-control" placeholder="用户名">
  </div>

  <div class="input-group">
    <input type="text" class="form-control" placeholder="您的电子邮件">
    <span class="input-group-text">@example.com</span>
  </div>
</form>
自己尝试 »

输入组大小

对于小型输入组,使用 .input-group-sm 类,对于大型输入组,使用 .input-group-lg

小型
默认
大型

示例

<div class="input-group mb-3 input-group-sm">
   <span class="input-group-text">小型</span>
  <input type="text" class="form-control">
</div>

<div class="input-group mb-3">
  <span class="input-group-text">默认</span>
  <input type="text" class="form-control">
</div>

<div class="input-group mb-3 input-group-lg">
  <span class="input-group-text">大型</span>
  <input type="text" class="form-control">
</div>
自己尝试 »

多个输入和帮助文本

添加多个输入或附加项

人员

示例

<!-- 多个输入 -->
<div class="input-group mb-3">
  <span class="input-group-text">人员</span>
  <input type="text" class="form-control" placeholder="姓">
  <input type="text" class="form-control" placeholder="名">
</div>

<!-- 多个附加项/帮助文本 -->
<div class="input-group mb-3">
  <span class="input-group-text">一</span>
  <span class="input-group-text">二</span>
  <span class="input-group-text">三</span>
  <input type="text" class="form-control">
</div>
自己尝试 »


带复选框和单选按钮的输入组

您也可以使用复选框或单选按钮代替文本

示例

<div class="input-group mb-3">
  <div class="input-group-text">
    <input type="checkbox">
  </div>
  <input type="text" class="form-control" placeholder="一些文本">
</div>

<div class="input-group mb-3">
  <div class="input-group-text">
    <input type="radio">
  </div>
  <input type="text" class="form-control" placeholder="一些文本">
</div>
自己尝试 »

带按钮的输入组

示例

<div class="input-group mb-3">
  <button class="btn btn-outline-primary" type="button">基本按钮</button>
  <input type="text" class="form-control" placeholder="一些文本">
</div>

<div class="input-group mb-3">
  <input type="text" class="form-control" placeholder="搜索">
  <button class="btn btn-success" type="submit">去</button>
</div>

<div class="input-group mb-3">
  <input type="text" class="form-control" placeholder="一些聪明的话..">
  <button class="btn btn-primary" type="button">确定</button>
  <button class="btn btn-danger" type="button">取消</button>
</div>
自己尝试 »

带下拉按钮的输入组

在输入组中添加下拉按钮。请注意,您不需要像平时一样使用 .dropdown 包装器。

示例

<div class="input-group mt-3 mb-3">
  <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown">
    下拉按钮
  </button>
  <ul class="dropdown-menu">
    <li><a class="dropdown-item" href="#">链接 1</a></li>
    <li><a class="dropdown-item" href="#">链接 2</a></li>
    <li><a class="dropdown-item" href="#">链接 3</a></li>
  </ul>
  <input type="text" class="form-control" placeholder="用户名">
</div>
自己尝试 »


×

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.