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

Paste_Image.png
一、表单
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。

例子

Paste_Image.png

引入bootstrap样式前

Paste_Image.png

<p>
引入bootstrap样式后

Paste_Image.png
2.内联表单

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

Paste_Image.png

例子

Paste_Image.png

引入以上所述的bootstrap样式前

Paste_Image.png

引入以上所述的bootstrap样式后

Paste_Image.png

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

例子
小于768px时:

Paste_Image.png

大于768px时:

Paste_Image.png
3.表单合组

//前后增加片段
<div class=”input-group”>
<div class=”input-group-addon”>¥</div>
<input class=”form-control” type=”text” />
<div class=”input-group-addon”>.00</div>
</div>

例子

Paste_Image.png

引入bootstrap样式前

Paste_Image.png

引入bootstrap样式后


Paste_Image.png
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表示和父元素样式同步

例子

Paste_Image.png

引入bootstrap样式前

Paste_Image.png

引入bootstrap样式后

Paste_Image.png
5.复选框和单选框

//设置复选框,在一行
<div class=”checkbox”>
<label>
<input type=”checkbox” />体育
</label>
</div>
<div class=”checkbox”>
<label>
<input type=”checkbox”>音乐
</label>
</div>

例子

Paste_Image.png

引入bootstrap样式前

Paste_Image.png

引入bootstrap样式后

Paste_Image.png

//设置禁用的复选框
<div class=”checkbox disabled”>
<label>
<input type=”checkbox” disabled>音乐
</label>
</div>

例子

Paste_Image.png

引入bootstrap样式前

Paste_Image.png

引入bootstrap样式后

Paste_Image.png

//设置内联一行显示的复选框
<label class=”checkbox-inline”>
<input type=”checkbox”>体育
</label>
<label class=”checkbox-inline disabled”>
<input type=”checkbox” disabled>音乐
</label>

例子

Paste_Image.png

引入bootstrap样式后

Paste_Image.png

//设置单选框
<div class=”radio disabled”>
<label>
<input type=”radio” name=”sex” disabled>男
</label>
</div>

例子

Paste_Image.png

引入bootstrap样式前

Paste_Image.png

引入bootstrap样式后

Paste_Image.png
6.下拉列表

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

例子

Paste_Image.png

引入bootstrap样式前

Paste_Image.png

引入bootstrap样式后

Paste_Image.png
7.校验状态

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

注:还有其他状态如下
样式 说明
has-error 错误状态
has-success 成功状态
has-warning 警告状态

例子

Paste_Image.png

引入以上阐述的bootstrap样式前

Paste_Image.png

引入以上阐述的bootstrap样式后

Paste_Image.png

//label标签同步相应状态
<label class=”control-label”>Input width success</label>

例子

Paste_Image.png

引入以上所述的bootstrap样式前

Paste_Image.png

引入以上所述的bootstrap样式后

Paste_Image.png
8.添加额外的图标

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

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

样式                  说明

glyhicon-ok 成功状态
Glyphicon-warning-sign 警告状态
Glyphicon-remove 错误状态

例子

Paste_Image.png

引入以上所述的bootstrap样式前

Paste_Image.png

引入以上所述的bootstrap样式后

Paste_Image.png
9.控制状态

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

例子

Paste_Image.png

引入bootstrap样式前

Paste_Image.png

引入bootstrap样式后

Paste_Image.png

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

例子

Paste_Image.png

引入bootstrap样式前

Paste_Image.png

引入bootstrap样式后

Paste_Image.png
二、图片
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”>

例子

Paste_Image.png

引入bootstrap样式前

Paste_Image.png

引入bootstrap样式后

Paste_Image.png

//响应式图片
<img src=”img/pic.png” alt=”图片” class=”img-responsive” />

例子

Paste_Image.png

本文作者lilyping
越努力,越幸运
原文链接:https://www.jianshu.com/u/3908e601f4ec
微信公众号:BestLilyPing
github:https://github.com/lilyping
Demos源码地址:https://github.com/lilyping

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,233评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,013评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,030评论 0 241
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,827评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,221评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,542评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,814评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,513评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,225评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,497评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,998评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,342评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,986评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,055评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,812评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,560评论 2 271
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,461评论 2 266

推荐阅读更多精彩内容

  • Bootstrap是什么? 一套易用、优雅、灵活、可扩展的前端工具集--BootStrap。GitHub上介绍 的...
    凛0_0阅读 10,687评论 3 184
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,099评论 18 139
  • 以下是Bootstrap--表格和按钮样式的相关知识,希望对你们有所帮助: 一、表格 1.基本格式//实现基本的表...
    lilyping阅读 3,576评论 0 12
  • 笔记参考自《响应式Web设计:HTML5和CSS3实践》,2013年出版内容说不上最新。如下是全书的章的目录:第 ...
    于晓鱼阅读 864评论 0 1
  • 原文出处 http://blog.poetries.top/2016/11/19/bootstrap-review...
    程序员poetry阅读 6,957评论 0 42