BootStrap【表格二、基础表单、被支持的控件、表单状态】(二)-全面详解(学习总结---从入门到深化)

目录

表格二

表单_基础表单

表单_被支持的控件

表单_表单状态


表格二

紧缩表格

通过添加 .table-condensed 类可以让表格更加紧凑,单元格中的内补(padding)均会减半

html 复制代码
<table class="table table-condensed table-bordered">
    <tr>
        <td>表格</td>
        <td>表格</td>
    </tr>
    <tr>
        <td>表格</td>
        <td>表格</td>
    </tr>
    <tr>
        <td>表格</td>
        <td>表格</td>
    </tr>
    <tr>
        <td>表格</td>
        <td>表格</td>
    </tr>
</table>

状态类

通过这些状态类可以为行或单元格设置颜色

|-------------|--------------------|
| Class | 描述 |
| .active | 鼠标悬停在行或单元格上时所设置的颜色 |
| .success | 标识成功或积极的动作 |
| .info | 标识普通的提示信息或动作 |
| .warning | 标识警告或需要用户注意 |
| .danger | 标识危险或潜在的带来负面影响的动作 |

html 复制代码
<table class="table table-condensed table-bordered">
    <tr class="active">
        <td>表格</td>
        <td>表格</td>
    </tr>
    <tr class="success">
        <td>表格</td>
        <td>表格</td>
    </tr>
    <tr class="warning">
        <td>表格</td>
        <td>表格</td>
    </tr>
    <tr class="danger">
        <td>表格</td>
        <td>表格</td>
    </tr>
    <tr class="info">
        <td>表格</td>
        <td>表格</td>
    </tr>
</table>

响应式表格

将任何 .table 元素包裹在 .table-responsive 元素内,即可创建响应式表格,其会在小屏幕设备上(小于768px)水平滚动。当屏幕大于768px 宽度时,水平滚动条消失

html 复制代码
<div class="table-responsive">
    <table class="table table-condensed table-bordered">
        <tr class="active">
            <td>这是一条表格内容数据,撑开表格</td>
            <td>这是一条表格内容数据,撑开表格</td>
        </tr>
        <tr class="success">
            <td>这是一条表格内容数据,撑开表格</td>
            <td>这是一条表格内容数据,撑开表格</td>
        </tr>
        <tr class="warning">
            <td>这是一条表格内容数据,撑开表格</td>
            <td>这是一条表格内容数据,撑开表格</td>
        </tr>
        <tr class="danger">
            <td>这是一条表格内容数据,撑开表格</td>
            <td>这是一条表格内容数据,撑开表格</td>
        </tr>
        <tr class="info">
            <td>这是一条表格内容数据,撑开表格</td>
            <td>这是一条表格内容数据,撑开表格</td>
        </tr>
    </table>
</div>

表单_基础表单

基本实例

单独的表单控件会被自动赋予一些全局样式。所有设置了**.form-control类的 <input><textarea><select> 元素都将被默认设置宽度属性为width: 100%;** 。 将label元素和前面提到的控件包裹在**.form-group**中可以获得最好的排列

html 复制代码
<form>
  <div class="form-group">
    <label for="exampleInputEmail1">Emailaddress</label>
    <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Email">
  </div>
  <div class="form-group">
    <label for="exampleInputPassword1">Password</label>
    <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
  </div>
  <div class="form-group">
    <label for="exampleInputFile">File input</label>
    <input type="file"  id="exampleInputFile">
    <p class="help-block">Example block-level help text here.</p>
  </div>
  <div class="checkbox">
    <label>
      <input type="checkbox"> Check me out
    </label>
  </div>
  <button type="submit" class="btn btn-default">Submit</button>
</form>

内联表单

为**<form>** 元素添加**.form-inline** 类可使其内容左对齐并且表现为 inline-block 级别的控件。只适用于视口(viewport)至少在 768px 宽度时(视口宽度再小的话就会使表单折叠)。

html 复制代码
<form class="form-inline">
    <div class="form-group">
        <label for="exampleInputName2">Name</label>
        <input type="text" class="form-control" id="exampleInputName2" placeholder="Jane Doe">
    </div>
    <div class="form-group">
        <label for="exampleInputEmail2">Email</label>
        <input type="email" class="form-control" id="exampleInputEmail2" placeholder="jane.doe@example.com">
    </div>
    <button type="submit" class="btn btn-default">Send invitation</button>
</form>
html 复制代码
<form class="form-inline">
    <div class="form-group">
        <div class="input-group">
            <div class="input-group-addon">$</div>
            <input type="text" class="form-control" id="exampleInputAmount" placeholder="Amount">
            <div class="input-group-addon">.00</div>
        </div>
    </div>
    <button type="submit" class="btn btn-primary">Transfer cash</button>
</form>

水平排列的表单

通过为表单添加**.form-horizontal类,并联合使用 Bootstrap 预置的栅格类,可以将 label标签和控件组水平并排布局。这样做将改变.form-group**的行为,使其表现为栅格系统中的行(row),因此就无需再额外添加 .row

html 复制代码
<form class="form-horizontal">
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Email</label>
    <div class="col-sm-10">
      <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Password</label>
    <div class="col-sm-10">
      <input type="password" class="form-control" id="inputPassword3" placeholder="Password">
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <div class="checkbox">
        <label>
          <input type="checkbox"> Remember me
        </label>
      </div>
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-default">Sign in</button>
    </div>
  </div>
</form>
67
8

表单_被支持的控件

表单布局实例中展示了其所支持的标准表单控件

输入框

包括大部分表单控件、文本输入域控件,还支持所有 HTML5 类型的输入控件: text 、 password 、 datetime 、 datetime-local 、 date 、 month 、time 、 week 、 number 、 email 、 url 、 search 、 tel 和 color

必须添加类型声明

只有正确设置了 type 属性的输入控件才能被赋予正确的样式。

html 复制代码
<input type="text" class="form-control" placeholder="Text input">

文本域

支持多行文本的表单控件。可根据需要改变rows属性

html 复制代码
<textarea class="form-control" rows="3"></textarea>

多选和单选框

多选框(checkbox)用于选择列表中的一个或多个选项,而单选框(radio)用于从多个选项中只选择一个

html 复制代码
<div class="checkbox">
    <label>
        <input type="checkbox" value="">
       Option one is this and that&mdash;be sure to include why it's great
    </label>
</div>
<div class="checkbox disabled">
    <label>
        <input type="checkbox" value="" disabled>
       Option two is disabled
    </label>
</div>
<div class="radio">
    <label>
        <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>
       Option one is this and that&mdash;be sure to include why it's great
    </label>
</div>
<div class="radio">
    <label>
        <input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">
       Option two can be something else and selecting it will deselect option one
    </label>
</div>
<div class="radio disabled">
    <label>
        <input type="radio" name="optionsRadios" id="optionsRadios3" value="option3" disabled>
       Option three is disabled
    </label>
</div>

下拉列表(select)

注意,很多原生选择菜单 - 即在 Safari 和 Chrome 中 - 的圆角是无法通过修改border-radius属性来改变的

html 复制代码
<select class="form-control">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
</select>

静态控件

如果需要在表单中将一行纯文本和label元素放置于同一行,为**<p>元素添加.form-control-static** 类即可

html 复制代码
<form class="form-horizontal">
    <div class="form-group">
        <label class="col-sm-2 control-label">Email</label>
        <div class="col-sm-10">
            <p class="form-control-static">email@example.com</p>
        </div>
    </div>
    <div class="form-group">
       <label for="inputPassword" class="col-sm-2 control-label">Password</label>
        <div class="col-sm-10">
            <input type="password" class="form-control" id="inputPassword" placeholder="Password">
        </div>
    </div>
</form>

表单_表单状态

焦点状态

我们将某些表单控件的默认outline 样式移除,然后对**:focus状态赋予box-shadow**属性

html 复制代码
<div class="form-group">
     <div class="col-sm-10">
         <input type="password" class="form-control" id="inputPassword" placeholder="Password">
     </div>
</div>

禁用状态

为输入框设置 disabled 属性可以禁止其与用户有任何交互(焦点、输入等)。被禁用的输入框颜色更浅,并且还添加了 not-allowed 鼠标状态

html 复制代码
<div class="form-group">
    <div class="col-sm-10">
        <input class="form-control" id="disabledInput" type="text" placeholder="Disabled input here..." disabled>
    </div>
</div>

只读状态

为输入框设置 readonly 属性可以禁止用户修改输入框中的内容。处于只读状态的输入框颜色更浅(就像被禁用的输入框一样),但是仍然保留标准的鼠标状态

html 复制代码
<input class="form-control" type="text" placeholder="Readonly input here..." readonly>

校验状态

Bootstrap 对表单控件的校验状态,如 error、warning 和 success状态,都定义了样式。使用时,添加 .has-warning 、 .has-error 或 .has-success 类到这些控件的父元素即可。任何包含在此元素之内的 .control-label 、 .form-control 和 .help-block 元素都将接受这些校验状态的样式

html 复制代码
<div class="form-group has-success">
    <label class="control-label" for="inputSuccess1">Input with success</label>
    <input type="text" class="form-control" id="inputSuccess1" aria-describedby="helpBlock2">
</div>
<div class="form-group has-warning">
    <label class="control-label" for="inputWarning1">Input with warning</label>
    <input type="text" class="form-control" id="inputWarning1">
</div>
<div class="form-group has-error">
    <label class="control-label" for="inputError1">Input with error</label>
    <input type="text" class="form-control" id="inputError1">
</div>

控件尺寸

通过**.input-lg类似的类可以为控件设置高度,通过.col-lg-***类似的类可以为控件设置宽度

html 复制代码
<input class="form-control input-lg" type="text" placeholder=".input-lg">
<input class="form-control" type="text" placeholder="Default input">
<input class="form-control input-sm" type="text" placeholder=".input-sm">
相关推荐
枫叶丹442 分钟前
【在Linux世界中追寻伟大的One Piece】进程信号
linux·运维·服务器
灯火不休ᝰ2 小时前
[win7] win7系统的下载及在虚拟机中详细安装过程(附有下载文件)
linux·运维·服务器
Мартин.3 小时前
[Meachines] [Easy] Sea WonderCMS-XSS-RCE+System Monitor 命令注入
前端·xss
昨天;明天。今天。4 小时前
案例-表白墙简单实现
前端·javascript·css
数云界4 小时前
如何在 DAX 中计算多个周期的移动平均线
java·服务器·前端
风清扬_jd4 小时前
Chromium 如何定义一个chrome.settingsPrivate接口给前端调用c++
前端·c++·chrome
安冬的码畜日常4 小时前
【玩转 JS 函数式编程_006】2.2 小试牛刀:用函数式编程(FP)实现事件只触发一次
开发语言·前端·javascript·函数式编程·tdd·fp·jasmine
ChinaDragonDreamer4 小时前
Vite:为什么选 Vite
前端
小御姐@stella4 小时前
Vue 之组件插槽Slot用法(组件间通信一种方式)
前端·javascript·vue.js
GISer_Jing4 小时前
【React】增量传输与渲染
前端·javascript·面试