表单控件

为 input 和 input 等文本表单控件提供自定义样式、大小、焦点状态等的升级。

更新于: 2023-04-30 14:28:21 查看: 526

发布于: 2021-8-31 13:48 发布者: 大米

例子

<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">Email 地址</label>
<input type="email" class="form-control" id="exampleFormControlInput1" placeholder="name@example.com">
</div>
<div class="mb-3">
<label for="exampleFormControlTextarea1" class="form-label">textarea 文本输入框</label>
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3"></textarea>
</div>

尺寸

使用 .form-control-lg 和 .form-control-sm 等类设置高度。
<input class="form-control form-control-lg" type="text" placeholder=".form-control-lg" aria-label=".form-control-lg example">
<input class="form-control" type="text" placeholder="Default input" aria-label="default input example">
<input class="form-control form-control-sm" type="text" placeholder=".form-control-sm" aria-label=".form-control-sm example">

禁用 

在输入上添加 disabled 的布尔属性,使其显示为灰色,并删除指针事件。
<input class="form-control" type="text" placeholder="Disabled input" aria-label="Disabled input example" disabled>
<input class="form-control" type="text" placeholder="Disabled readonly input" aria-label="Disabled input example" disabled readonly>

只读 

在输入上添加 readonly 布尔属性以防止修改输入的值。只读输入显示得更轻(就像禁用的输入一样), 但保留标准光标。
<input class="form-control" type="text" placeholder="Readonly input here..." aria-label="readonly input example" readonly>

只读纯文本

如果希望表单中的 <input readonly> 元素设置为纯文本样式,请使用 .form-control-plaintext 删除默认表单字段样式并保留正确的边距和填充。
  <div class="mb-3 row">
<label for="staticEmail" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
  <input type="text" readonly class="form-control-plaintext" id="staticEmail" value="email@example.com">
</div>
</div>
<div class="mb-3 row">
<label for="inputPassword" class="col-sm-2 col-form-label">Password</label>
<div class="col-sm-10">
  <input type="password" class="form-control" id="inputPassword">
</div>
</div>
<form class="row g-3">
<div class="col-auto">
<label for="staticEmail2" class="visually-hidden">Email</label>
<input type="text" readonly class="form-control-plaintext" id="staticEmail2" value="email@example.com">
</div>
<div class="col-auto">
<label for="inputPassword2" class="visually-hidden">Password</label>
<input type="password" class="form-control" id="inputPassword2" placeholder="Password">
</div>
<div class="col-auto">
<button type="submit" class="btn btn-primary mb-3">Confirm identity</button>
</div>
</form>

文件输入

<div class="mb-3">
<label for="formFile" class="form-label">Default file input example</label>
<input class="form-control" type="file" id="formFile">
</div>
<div class="mb-3">
<label for="formFileMultiple" class="form-label">Multiple files input example</label>
<input class="form-control" type="file" id="formFileMultiple" multiple>
</div>
<div class="mb-3">
<label for="formFileDisabled" class="form-label">Disabled file input example</label>
<input class="form-control" type="file" id="formFileDisabled" disabled>
</div>
<div class="mb-3">
<label for="formFileSm" class="form-label">Small file input example</label>
<input class="form-control form-control-sm" id="formFileSm" type="file">
</div>
<div>
<label for="formFileLg" class="form-label">Large file input example</label>
<input class="form-control form-control-lg" id="formFileLg" type="file">
</div>

颜色

<label for="exampleColorInput" class="form-label">Color picker</label>
<input type="color" class="form-control form-control-color" id="exampleColorInput" value="#563d7c" title="Choose your color">

下拉选择框

数据列表允许您创建一组可以从 <input> 中访问(并自动完成)的 <option> 组。这些元素类似于 <select> 元素,但具有更多菜单样式限制和差异。虽然大多数浏览器和操作系统都支持 <datalist> 元素,但它们的样式最多是不一致的。
<label for="exampleDataList" class="form-label">Datalist example</label>
<input class="form-control" list="datalistOptions" id="exampleDataList" placeholder="Type to search...">
<datalist id="datalistOptions">
<option value="San Francisco">
<option value="New York">
<option value="Seattle">
<option value="Los Angeles">
<option value="Chicago">
</datalist>

扫描二维码,手机查看
声明:部分数据/图片来源互联网,不代表Hluse Doc.,真实性请妥善甄别。