bootstrap 学习笔记(4)---- 按钮

日常咱们本身写按钮,此次不用咱们本身写 了,直接应用bootstrap中的按钮样式,就能设计出很漂亮的按钮样式。接下来就让咱们一块儿学习吧。html

一、能够做为按钮使用的标签或元素:<a><button><input>编程

eg:<a class="btn btn-default" href="#" role="button">Link</a> bootstrap

<button class="btn btn-default" type="submit">Button</button> <input class="btn btn-default" type="button" value="Input"> <input class="btn btn-default" type="submit" value="Submit">

二、针对组件的注意事项浏览器

虽然按钮类能够应用到 <a> 和 <button> 元素上,可是,导航和导航条组件只支持 <button> 元素。ide

三、连接被做为按钮使用时的注意事项工具

若是 <a> 元素被做为按钮使用 -- 并用于在当前页面触发某些功能 -- 而不是用于连接其余页面或连接当前页面中的其余部分,那么,务必为其设置 role="button" 属性。学习

四、跨浏览器展示this

咱们总结的最佳实践是:强烈建议尽量使用 <button> 元素来得到在各个浏览器上得到相匹配的绘制效果。spa

 

另外,咱们还发现了 Firefox <30 版本的浏览器上出现的一个 bug,其表现是:阻止咱们为基于 <input> 元素所建立的按钮设置 line-height 属性,这就致使在 Firefox 浏览器上不能彻底和其余按钮保持一致的高度。设计

五、预约义样式

使用下面列出的类能够快速建立一个带有预约义样式的按钮。

 <!-- Standard button -->

 <button type="button" class="btn">(无样式)Default</button>

<!-- Standard button --> <button type="button" class="btn btn-default">(默认样式)Default</button> <!-- Provides extra visual weight and identifies the primary action in a set of buttons --> <button type="button" class="btn btn-primary">(首选项)Primary</button> <!-- Indicates a successful or positive action --> <button type="button" class="btn btn-success">(成功)Success</button> <!-- Contextual button for informational alert messages --> <button type="button" class="btn btn-info">(通常信息)Info</button> <!-- Indicates caution should be taken with this action --> <button type="button" class="btn btn-warning">(警告)Warning</button> <!-- Indicates a dangerous or potentially negative action --> <button type="button" class="btn btn-danger">(危险)Danger</button> <!-- Deemphasize a button by making it look like a link while maintaining button behavior --> <button type="button" class="btn btn-link">(连接)Link</button>
颜色值以下图:

6.尺寸:

 

禁用状态:经过为按钮的背景设置  属性就能够呈现出没法点击的效果。
button 元素 为  元素添加  属性,使其表现出禁用状态。
eg:
须要让按钮具备不一样尺寸吗?使用 .btn-lg.btn-sm 或 .btn-xs 就能够得到不一样尺寸的按钮。
块级元素
经过给按钮添加 .btn-block 类能够将其拉伸至父元素100%的宽度,并且按钮也变为了块级(block)元素。
7.激活状态:
当按钮处于激活状态时,其表现为被按压下去(底色更深、边框夜色更深、向内投射阴影)。对于 <button> 元素,是经过 :active 状态实现的。对于 <a> 元素,是经过 .active 类实现的。然而,你还能够将 .active 应用到 <button>上(包含 aria-pressed="true" 属性)),并经过编程的方式使其处于激活状态。
button 元素:因为 :active 是伪状态,所以无需额外添加,可是在须要让其表现出一样外观的时候能够添加 .active 类。
eg:<button type="button" class="btn btn-primary btn-lg active">Primary button</button>
<button type="button" class="btn btn-default btn-lg active">Button</button>

8.
.btn-lg.btn-sm.btn-xs.btn-block<button>:active<a>.active.active<button>aria-pressed="true":active.active<button type="button" class="btn btn-primary btn-lg active">Primary button</button>
<button type="button" class="btn btn-default btn-lg active">Button</button>
opacity<button>disabled<button type="button" class="btn btn-lg btn-primary" disabled="disabled">Primary button</button>
  <button type="button" class="btn btn-default btn-lg" disabled="disabled">Button</button>

跨浏览器兼容性

若是为 <button> 元素添加 disabled 属性,Internet Explorer 9 及更低版本的浏览器将会把按钮中的文本绘制为灰色,并带有恶心的阴影,目前咱们尚未解决办法。

 

连接(<a>)元素

为基于 <a> 元素建立的按钮添加 .disabled 类。

eg:
<a href="#" class="btn btn-primary btn-lg disabled" role="button">Primary link</a> <a href="#" class="btn btn-default btn-lg disabled" role="button">Link</a>

咱们把 .disabled 做为工具类使用,就像 .active 类同样,所以不须要增长前缀。

相关文章
相关标签/搜索