美文网首页
Bootstrap[第四章 表单和图片]

Bootstrap[第四章 表单和图片]

作者: GXD_小男孩 | 来源:发表于2019-05-22 16:34 被阅读0次

一.表单

1.基本格式

//实现基本的表单样式
<form>
<div class="form-group">
<label>电子邮件</label>
<input type="email" class="form-control" placeholder="请输入您的电子邮件">
</div>
<div class="form-group">
<label>密码</label>
<input type="password" class="form-control" placeholder="请输入您的密码">
</div>
</form>
效果图

注:只有正确设置了输入框的 type 类型,才能被赋予正确的样式。支持的输入框控件包括:text、password、datetime、datetime-local、date、month、time、week、number、email、url、search、tel 和 color。

2.内联表单

//让表单左对齐浮动,并表现为 inline-block 内联块结构
<form class="form-inline">
内联表单

注:当小于 768px,会恢复独占样式

3.表单合组

//前后增加片段
<div class="input-group">
  <div class="input-group-addon">¥</div>
  <input type="text" class="form-control">
  <div class="input-group-addon">.00</div>
</div>
表单合组

4.水平排列

//让表单内的元素保持水平排列
<form class="form-horizontal">
    <div class="form-group">
      <label class="col-sm-2 control-label">电子邮件</label>
      <div class="col-sm-10">
      <input type="email" class="form-control" placeholder="请输入您的电子邮件">
    </div>
  </div>
</form>
水平排列

注:这里用到了 col-sm 栅格系统,后面章节会重点讲解,而 control-label 表示和父元素样式同步。

5.复选框和单选框

//设置复选框,在一行
<div class="checkbox">
<label>
<input type="checkbox">体育
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox">音乐
</label>
</div>
//设置禁用的复选框
<div class="checkbox disabled">
<label>
<input type="checkbox" disabled>音乐
</label>
</div>
//设置内联一行显示的复选框
<label class="checkbox-inline">
<input type="checkbox">体育
</label>
<label class="checkbox-inline disabled">
<input type="checkbox" disabled>音乐
</label>//设置单选框
<div class="radio disabled">
<label>
<input type="radio" name="sex" disabled>男
</label>
</div>
复选框和单选框

6.下拉列表

//设置下拉列表
<select class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
下拉列表

7.校验状态

//设置为错误状态
<div class="form-group has-error">

注:还有其他状态如下:

样式 说明
has-error 错误状态
has-success 成功状态
has-warning 警告状态
//label 标签同步相应状态
<label class="control-label">Input with success</label>
校验状态

8.添加额外的图标

//文本框右侧内置文本图标
<div class="form-group has-feedback">
<label>电子邮件</label>
<input type="email" class="form-control">
<span class="glyphicon glyphicon-ok form-control-feedback"></span>
</div>

注:除了 glyphicon-ok 外,还有几个如下表:

样式 说明
glyphicon-ok 成功状态
glyphicon-warning-sign 警告状态
glyphicon-remove 错误状态
额外的图标

9.控制尺寸

//从大到小
<input type="password" class="form-control input-lg">
<input type="password" class="form-control">
<input type="password" class="form-control input-sm">

注:也可以设置父元素 form-group-lg、form-group-sm,来调整。


控制尺寸

二.图片

Bootstrap 提供了一些丰富的图片样式供开发者使用。

1.图片形状

//三种形状
<img src="img/pic.png" alt="图片" class="img-rounded">
<img src="img/pic.png" alt="图片" class="img-circle">
<img src="img/pic.png" alt="图片" class="img-thumbnail">
//响应式图片,可以根据窗口大小变动
<img src="img/pic.png" alt="图片" class="img-responsive">
三种形状

相关文章

  • Bootstrap[第四章 表单和图片]

    一.表单 1.基本格式 注:只有正确设置了输入框的 type 类型,才能被赋予正确的样式。支持的输入框控件包括:t...

  • Bootstrap表单和图片(四)

    1. 表单 1.1 基本样式 input class="form-control"用div class="form...

  • 前端框架Bootstrap--表单和图片

    一、表单 1. 基本样式 //实现基本的表单样式 电子邮件 密码 注:只有正确设置了输入框的ty...

  • bootstrapValidator

    bootstrap表单验证

  • 2018-11-21

    bootstrap大纲: 1、css样式 1)栅格系统 2)排版 3)代码 4)表格 5)表单 6)按钮 7)图片...

  • bootstrap表单

    表单布局 垂直表单(默认) 内联表单 水平表单 垂直表单或基本表单 基本的表单结构是 Bootstrap 自带的,...

  • 2019-04-09 表单(5)

    表单布局Bootstrap 提供了下列类型的表单布局: 垂直表单(默认) 内联表单 水平表单 1.垂直或基本表单 ...

  • 21天习惯养成打卡-day1

    遇到的问题 前端进行图片压缩 bootstrap框架表单的使用 解决方法 张鑫旭博客上的解决方案前端实现图片压缩上...

  • bootstrap表单

    垂直表单(默认) 内联表单 水平表单 垂直表单 也称基本表单基本的表单结构是 bootstrap 自带的创建基本表...

  • bootstrap 时间控件

    bootstrap日期时间表单组件http://www.bootcss.com/p/bootstrap-datet...

网友评论

      本文标题:Bootstrap[第四章 表单和图片]

      本文链接:https://www.haomeiwen.com/subject/clhuzqtx.html