Bootstrap 提供了一些选项来定义按钮的样式,具体如下表所示:
以下样式可用于< a >, < button >, 或 < input > 元素上:
<table border="1" cellpadding="2" cellspacing="0" style="font-size:undefined; border-collapse:collapse; margin-top:10px; margin-bottom:10px"><tbody style="background-color:inherit"><tr style="background-color:inherit"><th style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit; width:98.4000015258789px"><span style="font-family:Comic Sans MS; font-size:14px">类</span></th><th style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit; width:436px"><span style="font-family:Comic Sans MS; font-size:14px">描述</span></th></tr><tr style="background-color:inherit"><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">.btn</span></td><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">为按钮添加基本样式</span></td></tr><tr style="background-color:inherit"><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:27.0000030517578px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">.btn-default</span></td><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:27.0000030517578px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">默认/标准按钮</span></td></tr><tr style="background-color:inherit"><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:30.199993896484386px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">.btn-primary</span></td><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:30.199993896484386px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">原始按钮样式(未被操作)</span></td></tr><tr style="background-color:inherit"><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">.btn-success</span></td><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">表示成功的动作</span></td></tr><tr style="background-color:inherit"><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">.btn-info</span></td><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">该样式可用于要弹出信息的按钮</span></td></tr><tr style="background-color:inherit"><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">.btn-warning</span></td><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">表示需要谨慎操作的按钮</span></td></tr><tr style="background-color:inherit"><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">.btn-danger</span></td><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">表示一个危险动作的按钮操作</span></td></tr><tr style="background-color:inherit"><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">.btn-link</span></td><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">让按钮看起来像个链接 (仍然保留按钮行为)</span></td></tr><tr style="background-color:inherit"><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">.btn-lg</span></td><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">制作一个大按钮</span></td></tr><tr style="background-color:inherit"><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">.btn-sm</span></td><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">制作一个小按钮</span></td></tr><tr style="background-color:inherit"><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">.btn-xs</span></td><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">制作一个超小按钮</span></td></tr><tr style="background-color:inherit"><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">.btn-block</span></td><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">块级按钮(拉伸至父元素100%的宽度)</span></td></tr><tr style="background-color:inherit"><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:24.5999755859375px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">.active</span></td><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:24.5999755859375px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">按钮被点击</span></td></tr><tr style="background-color:inherit"><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">.disabled</span></td><td style="word-break:break-all; border:1px solid rgb(153,153,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"><span style="font-family:Comic Sans MS; font-size:14px">禁用按钮<br/></span></td></tr></tbody></table>
首先看下不同颜色的按钮:
~~~
<html lang="en">
<head>
<!--网站编码格式,UTF-8 国际编码,GBK或 gb2312 中文编码-->
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="Keywords" content="关键词一,关键词二">
<meta name="Description" content="网站描述内容">
<meta name="Author" content="Yvette Lau">
<meta name = "viewport" content = " width = device-width, initial-scale = 1 ">
<title>BootstrapDemo</title>
<!--css js 文件的引入-->
<link rel="stylesheet" type="text/css" href="../bootstrap-3.3.5-dist/css/bootstrap.min.css">
</head>
<body style="padding: 20px;">
<!-- 标准的按钮 -->
<button type="button" class="btn btn-default">默认按钮</button>
<!-- 提供额外的视觉效果,标识一组按钮中的原始动作 -->
<button type="button" class="btn btn-primary">原始按钮</button>
<!-- 表示一个成功的或积极的动作 -->
<button type="button" class="btn btn-success">成功按钮</button>
<!-- 用于要弹出信息的按钮 -->
<button type="button" class="btn btn-info">信息按钮</button>
<!-- 表示应谨慎操作的动作 -->
<button type="button" class="btn btn-warning">警告按钮</button>
<!-- 表示一个危险动作的按钮 -->
<button type="button" class="btn btn-danger">危险按钮</button>
<!-- 让按钮看起来像一个链接,但同时保持按钮的行为 -->
<button type="button" class="btn btn-link">链接按钮</button>
</body>
</html>
~~~
效果:
![](https://box.kancloud.cn/2016-04-07_570603f43f5b6.jpg)
btn-default / btn-primary /btn-success/ btn-info/ btn-warning/ btn-danger/ btn-link给按钮加上了不同的样式。
### 按钮大小
鉴于head部分都是相同的,只列出Body的内容。
~~~
<body style="padding: 20px;width:500px;">
<!-- 标准的按钮 -->
<button type="button" class="btn btn-default">默认按钮</button>
<button type="button" class="btn btn-lg btn-default">大的默认按钮</button>
<br/><br/>
<!-- 提供额外的视觉效果,标识一组按钮中的原始动作 -->
<button type="button" class="btn btn-primary">原始按钮</button>
<button type="button" class="btn btn-sm btn-primary">小的原始按钮</button>
<br/><br/>
<!-- 表示一个成功的或积极的动作 -->
<button type="button" class="btn btn-success">成功按钮</button>
<button type="button" class="btn btn-xs btn-success">特别小的成功按钮</button>
<br/><br/>
<!-- 用于要弹出信息的按钮 -->
<button type="button" class="btn btn-info">信息按钮</button><br/><br/>
<button type="button" class="btn btn-block btn-info">块级信息按钮</button>
</body>
~~~
效果如下所示:
![](https://box.kancloud.cn/2016-04-07_570603f455cb6.jpg)
### 按钮状态
按钮分为active和disabled两种状态、
激活状态:按钮呈现出被按压的外观,即背景颜色变深、深色边框和阴影。
禁用状态:按钮颜色会变淡 50%,并失去渐变
看具体的例子:
~~~
<body style="padding: 20px;width:500px;">
<!-- 标准的按钮 -->
<button type="button" class="btn btn-default">默认按钮</button>
<button type="button" class="btn btn-default active">激活的默认按钮</button>
<br/><br/>
<!-- 提供额外的视觉效果,标识一组按钮中的原始动作 -->
<button type="button" class="btn btn-primary">原始按钮</button>
<button type="button" class="btn btn-primary active">激活的原始按钮</button>
<br/><br/>
<!-- 表示一个成功的或积极的动作 -->
<button type="button" class="btn btn-success">成功按钮</button>
<button type="button" class="btn btn-success active">激活的成功按钮</button>
<br/><br/>
<!-- 用于要弹出信息的按钮 -->
<button type="button" class="btn btn-info">信息按钮</button>
<button type="button" class="btn btn-info active">激活的信息按钮</button>
<br/><br/>
<button type="button" class="btn btn-default">默认按钮</button>
<button type="button" class="btn btn-default disabled">禁用的默认按钮</button>
<br/><br/>
<!-- 提供额外的视觉效果,标识一组按钮中的原始动作 -->
<button type="button" class="btn btn-primary">原始按钮</button>
<button type="button" class="btn btn-primary disabled">禁用的原始按钮</button>
<br/><br/>
<!-- 表示一个成功的或积极的动作 -->
<button type="button" class="btn btn-success">成功按钮</button>
<button type="button" class="btn btn-success disabled">禁用的成功按钮</button>
<br/><br/>
<!-- 用于要弹出信息的按钮 -->
<button type="button" class="btn btn-info">信息按钮</button>
<button type="button" class="btn btn-info disabled">禁用的信息按钮</button>
</body>
~~~
![](https://box.kancloud.cn/2016-04-07_570603f465419.jpg)
### 按钮标签
a,input都可以表现的像一个按钮,但是避免跨浏览器不一致,最好使用Button标签。
~~~
<body style="padding: 20px;">
<a class="btn btn-default" href="#" role="button">超链接按钮</a>
<button class="btn btn-default btn-primary" type="submit">button按钮</button>
<input class="btn btn-default btn-success" type="button" value="input按钮">
<input class="btn btn-default btn-info" type="submit" value="submit按钮">
</body>
~~~
![](https://box.kancloud.cn/2016-04-07_570603f47581d.jpg)
- 前言
- jQuery轮播图插件
- JS模拟事件操作
- JS闭包与变量
- JS绑定事件
- HTML5之file控件
- JavaScript的this词法
- JavaScript的this词法(二)
- JS this词法(三)
- JS检测浏览器插件
- JS拖拽组件开发
- number输入框
- Modernizr.js和yepnode.js
- DOM变化后事件绑定失效
- div和img之间的缝隙问题
- 详解JavaScript作用域
- bootstrap入门
- 表单验证(登录/注册)
- Bootstrap网格系统
- Bootstrap排版
- Bootstrap创建表单(一)
- Bootstrap表单(二)
- Bootstrap按钮
- Bootstrap图片
- Bootstrap字体图标(glyphicons)
- Bootstrap的aria-label和aria-labelledby
- Bootstrap下拉菜单
- Bootstrap按钮组
- Bootstrap按钮菜单
- Bootstrap输入框组
- Bootstrap导航元素
- Bootstrap导航栏
- sublimeText频频崩溃
- JQuery不同版本的差异(checkbox)
- Bootstrap面包屑导航、分页、标签、徽章
- Bootstrap警告
- Bootstrap进度条
- 前端的上传下载
- JS字符串的相关方法
- CSS3选择器(全)
- CSS3新增文本属性详述
- 利用CSS3实现图片切换特效
- CSS3新增颜色属性
- CSS3的border-radius属性详解
- JS创建对象几种不同方法详解
- JS实现继承的几种方式详述(推荐)
- CSS3响应式布局
- JS模块化开发(requireJS)
- 利用@font-face实现个性化字体
- 前端在html页面之间传递参数的方法
- CSS自动换行、强制不换行、强制断行、超出显示省略号
- 如何在Html中引入外部页面
- reactJS入门
- React组件生命周期
- 使用React实现类似快递单号查询效果
- ReactJS组件生命周期详述
- React 属性和状态详解