WEB前端网页设计-Bootstrap4 表单控件

文章详细介绍了Bootstrap4中的几种基本表单控件,包括input文本输入、textarea多行文本、checkbox复选框、radio单选框以及select下拉菜单的使用方法,提供了HTML代码示例和不同状态(如禁用)的展示。
摘要由CSDN通过智能技术生成

目录

Bootstrap4 表单控件

Bootstrap Input

Bootstrap textarea

Bootstrap 复选框(checkbox)

Bootstrap 单选框(Radio)

Bootstrap select 下拉菜单


Bootstrap4 表单控件

Bootstrap4 支持以下表单控件:

  • input
  • textarea
  • checkbox
  • radio
  • select

Bootstrap Input

Bootstrap 支持所有的 HTML5 输入类型: text, password, datetime, datetime-local, date, month, time, week, number, email, url, search, tel, 以及 color。

注意:: 如果 input 的 type 属性未正确声明,输入框的样式将不会显示。

以下实例使用两个 input 元素,一个是 text,一个是 password :

<div class="form-group">
  <label for="usr">用户名:</label>
  <input type="text" class="form-control" id="usr">
</div>
<div class="form-group">
  <label for="pwd">密码:</label>
  <input type="password" class="form-control" id="pwd">
</div>

Bootstrap textarea

以下实例演示了 textarea 的样式:

<div class="form-group">
  <label for="comment">评论:</label>
  <textarea class="form-control" rows="5" id="comment"></textarea>
</div>

Bootstrap 复选框(checkbox)

复选框用于让用户从一系列预设置的选项中进行选择,可以选一个或多个。

以下实例包含了三个选项。最后一个是禁用的:

<div class="form-check">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="">Option 1
  </label>
</div>
<div class="form-check">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="">Option 2
  </label>
</div>
<div class="form-check disabled">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="" disabled>Option 3
  </label>
</div>

使用 .form-check-inline 类可以让选项显示在同一行上:

<div class="form-check form-check-inline">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="">Option 1
  </label>
</div>
<div class="form-check form-check-inline">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="">Option 2
  </label>
</div>
<div class="form-check form-check-inline disabled">
  <label class="form-check-label">
    <input type="checkbox" class="form-check-input" value="" disabled>Option 3
  </label>
</div>

Bootstrap 单选框(Radio)

单选框用于让用户从一系列预设置的选项中进行选择,只能选一个。

以下实例包含了三个选项。最后一个是禁用的:

<div class="radio">
  <label><input type="radio" name="optradio">Option 1</label>
</div>
<div class="radio">
  <label><input type="radio" name="optradio">Option 2</label>
</div>
<div class="radio disabled">
  <label><input type="radio" name="optradio" disabled>Option 3</label>
</div>

使用 .radio-inline 类可以让选项显示在同一行上:

<label class="radio-inline"><input type="radio" name="optradio">Option 1</label>
<label class="radio-inline"><input type="radio" name="optradio">Option 2</label>
<label class="radio-inline"><input type="radio" name="optradio" disabled>Option 3</label>

Bootstrap select 下拉菜单

当您想让用户从多个选项中进行选择,但是默认情况下只能选择一个选项时,则使用选择框。

以下实例包含了两个下拉菜单:

<div class="form-group">
  <label for="sel1">下拉菜单:</label>
  <select class="form-control" id="sel1">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
  </select>
</div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你可知这世上再难遇我

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值