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


Bootstrap 4 输入组

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

使用 .input-group-prepend 在输入前面添加帮助文本,使用 .input-group-append 在输入后面添加帮助文本。

最后,添加 .input-group-text 类来设置指定的帮助文本的样式。

@
@example.com

示例

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

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

提示: 我们使用 .mb-3 实用工具类来确保输入组获得适当的底部边距。 阅读有关实用工具类的更多信息,请访问我们的 BS4 实用工具章节


输入组大小

使用 .input-group-sm 类表示小型输入组,使用 .input-group-lg 类表示大型输入组。

小型
默认
大型

示例

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


多个输入和帮助文本

添加多个输入或附加项

个人

示例

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

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

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

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

示例

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

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

输入组按钮

示例

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

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

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

带有下拉按钮的输入组

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

示例

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

输入组标签

将标签放在输入组之外,并记住 for 属性的值应与输入的 id 匹配。

点击标签,它将使输入获得焦点

@example.com

示例

<label for="demo">在此处输入您的电子邮件:</label>
<div class="input-group mb-3">
  <input type="text" class="form-control" placeholder="电子邮件" id="demo" name="email">
  <div class="input-group-append">
    <span class="input-group-text">@example.com</span>
  </div>
</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.