Bootstrap按鈕組

来源:http://www.cnblogs.com/xiaohuochai/archive/2017/07/03/7107129.html
-Advertisement-
Play Games

[1]使用方法 [2]基本用法 [3]按鈕工具欄 [4]按鈕尺寸 [5]嵌套分組 [6]垂直排列 [7]等分按鈕 ...


前面的話

  單個按鈕在Web頁面中的運用有時候並不能滿足我們的業務需求,常常會看到將多個按鈕組合在一起使用,比如富文本編輯器里的一組小圖標按鈕等。本文將詳細介紹Bootstrap按鈕組

 

使用方法

  按鈕組和下拉菜單組件一樣,需要依賴於button.js插件才能正常運行。不過我們同樣可以直接只調用bootstrap.js文件。因為這個文件已集成了button.js插件功能

  同樣地,因為Bootstrap的組件交互效果都是依賴於jQuery庫寫的插件,所以在使用bootstrap.js之前一定要先載入jquery.js才會產生效果

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>

 

基本用法

  按鈕組結構非常的簡單。使用一個名為“btn-group”的容器,把多個按鈕放到這個容器中

  為了向屏幕閱讀器的用戶傳達正確的按鈕分組,需要提供一個合適的 role 屬性。對於按鈕組合,應該是 role="group",對於toolbar(工具欄)應該是 role="toolbar"

  此外,按鈕組和工具欄應給定一個明確的label標簽,儘管設置了正確的 role 屬性,但是大多數輔助技術將不會正確的識讀他們。可以使用 aria-label,也可以使用aria-labelledby

  除了可以使用<button>元素之外,還可以使用其他標簽元素,比如<a>標簽。唯一要保證的是:不管使用什麼標簽,“.btn-group”容器里的標簽元素需要帶有類名“.btn”

<div class="btn-group">
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-step-backward"></span></button>
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-fast-backward"></span></button>
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-backward"></span></button>
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-play"></span></button>
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-pause"></span></button>
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-stop"></span></button>
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-forward "></span></button>
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-fast-forward"></span></button>
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-step-forward"></span></button>
</div>

 

按鈕工具欄

  在富文本編輯器中,將按鈕組分組排列在一起,比如說複製、剪切和粘貼一組;左對齊、中間對齊、右對齊和兩端對齊一組。Bootstrap框架按鈕工具欄也提供了這樣的製作方法,只需要將按鈕組“btn-group”按組放在一個大的容器“btn-toolbar”中

<div class="btn-toolbar">
  <div class="btn-group">
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-align-left"></span></button>
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-align-center"></span></button>
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-align-right"></span></button>
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-align-justify"></span></button>
  </div>
  <div class="btn-group">
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-indent-left"></span></button>
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-indent-right"></span></button>
  </div>
  <div class="btn-group">
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-font"></span></button>
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-bold"></span></button>
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-italic"></span></button>
  </div>
  <div class="btn-group">
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-text-height"></span></button>
    <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-text-width"></span></button>
  </div>
</div>

 

按鈕尺寸

  在介紹表單按鈕的博文中,我們知道按鈕是通過btn-lg、btn-sm和btn-xs三個類名來調整padding、font-size、line-height和border-radius屬性值來改變按鈕大小。那麼按鈕組的大小,我們也可以通過類似的方法:

    ☑  .btn-group-lg:大按鈕組

    ☑  .btn-group-sm:小按鈕組

    ☑  .btn-group-xs:超小按鈕組

  只需要在“.btn-group”類名上追加對應的類名,就可以得到不同大小的按鈕組

<div class="btn-group btn-group-lg">
  <button type="button" class="btn btn-default">1</button>
  <button type="button" class="btn btn-default">2</button>
  <button type="button" class="btn btn-default">3</button>
</div>
<div class="btn-group">
  <button type="button" class="btn btn-default">1</button>
  <button type="button" class="btn btn-default">2</button>
  <button type="button" class="btn btn-default">3</button>
</div>
<div class="btn-group btn-group-sm">
  <button type="button" class="btn btn-default">1</button>
  <button type="button" class="btn btn-default">2</button>
  <button type="button" class="btn btn-default">3</button>
</div>
<div class="btn-group btn-group-xs">
  <button type="button" class="btn btn-default">1</button>
  <button type="button" class="btn btn-default">2</button>
  <button type="button" class="btn btn-default">3</button>
</div>

 

嵌套分組

  很多時候,我們常把下拉菜單和普通的按鈕組排列在一起,實現類似於導航菜單的效果。使用的時候,只需要把當初製作下拉菜單的“dropdown”的容器換成“btn-group”,並且和普通的按鈕放在同一級

<div class="btn-group">
  <button class="btn btn-default" type="button">首頁</button>
  <button class="btn btn-default" type="button">產品展示</button>
  <button class="btn btn-default" type="button">案例分析</button>
  <button class="btn btn-default" type="button">聯繫我們</button>
  <div class="btn-group">
      <button class="btn btn-default dropdown-toggle" data-toggle="dropdown" type="button">關於我們 <span class="caret"></span></button>
    <ul class="dropdown-menu">
        <li><a href="##">公司簡介</a></li>
        <li><a href="##">企業文化</a></li>
        <li><a href="##">組織結構</a></li>
        <li><a href="##">客服服務</a></li>
    </ul>
  </div>
</div>

 

垂直排列

  預設地,按鈕組都是水平顯示的。但在實際運用當中,總會碰到垂直顯示的效果。在Bootstrap框架中也提供了這樣的風格。只需要把水平分組的“btn-group”類名換成“btn-group-vertical”即可

<div class="btn-group-vertical">
  <button class="btn btn-default" type="button">首頁</button>
  <button class="btn btn-default" type="button">產品展示</button>
  <button class="btn btn-default" type="button">案例分析</button>
  <button class="btn btn-default" type="button">聯繫我們</button>
  <div class="btn-group">
      <button class="btn btn-default dropdown-toggle" data-toggle="dropdown" type="button">關於我們<span class="caret"></span></button>
    <ul class="dropdown-menu">
        <li><a href="##">公司簡介</a></li>
        <li><a href="##">企業文化</a></li>
        <li><a href="##">組織結構</a></li>
        <li><a href="##">客服服務</a></li>
    </ul>
  </div>
</div>

 

等分按鈕

  等分按鈕的效果在移動端上特別的實用。整個按鈕組寬度是容器的100%,而按鈕組裡面的每個按鈕平分整個容器寬度。例如,如果按鈕組裡面有五個按鈕,那麼每個按鈕是20%的寬度,如果有四個按鈕,那麼每個按鈕是25%寬度,以此類推

  等分按鈕也常被稱為是自適應分組按鈕,其實現方法也非常的簡單,只需要在按鈕組“btn-group”上追加一個“btn-group-justified”類名

  實現原理非常簡單,把“btn-group-justified”模擬成表格(display:table),而且把裡面的按鈕模擬成表格單元格(display:table-cell)

  [註意]在製作等分按鈕組時,儘量使用<a>標簽元素來製作按鈕,因為使用<button>標簽元素時,使用display:table在部分瀏覽器下支持並不友好

.btn-group-justified {
  display: table;
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
}
.btn-group-justified > .btn,
.btn-group-justified > .btn-group {
  display: table-cell;
  float: none;
  width: 1%;
}
.btn-group-justified > .btn-group .btn {
  width: 100%;
}

  在上面的代碼中,.btn-group-justified > .btn設置了table-cell,而table-cell是不能設置margin的,而代碼中設置了-margin值,用來去除邊框,顯然不會生效。因此,去除重覆邊框的代碼應該是合併表格邊框—— border-collapse: collapse

<div class="btn-group btn-group-justified">
    <a class="btn btn-default" href="#">首頁</a>
    <a class="btn btn-default" href="#">產品展示</a>
    <a class="btn btn-default" href="#">案例分析</a>
    <a class="btn btn-default" href="#">聯繫我們</a>
</div>

  為了將 <button> 元素用於兩端對齊的按鈕組中,必須將每個按鈕包裹進一個按鈕組中。因為大部分的瀏覽器不能將CSS 應用到對齊的 <button> 元素上,但是,可以用按鈕式下拉菜單來解決這個問題

<div class="btn-group btn-group-justified">
    <div class="btn-group" role="group">
        <button class="btn btn-default" >首頁</button>
    </div>    
    <div class="btn-group" role="group">
        <button class="btn btn-default" >產品展示</button>
    </div>    
    <div class="btn-group" role="group">
        <button class="btn btn-default" >案例分析</button>
    </div>    
    <div class="btn-group" role="group">
        <button class="btn btn-default" >聯繫我們</button>
    </div>    
</div>

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 上傳頭像,自己感覺了好久,就是上傳文件唄其實,存在一個路徑,資料庫存儲這個路徑,然後展示給前端,啥都不說,看怎麼實現的。 資料庫設置如下 form 表單設計: 後端實現代碼 存儲路徑是 接下來是前端的展示 這裡說明下,這裡的後端實現上傳的頭像的代碼 在Windows上回報錯,說文件不存在,我試著去修 ...
  • 簡單工廠模式 簡單工廠模式是類的創建模式,又叫做靜態工廠方法模式。簡單工廠模式由一個工廠對象決定生產出哪一種產品類的實例。 為什麼要使用簡單工廠模式 原因很簡單:解耦。 LOL場景分析: LOL中目前有100多個英雄,各個人物的技能全都不同,具體英雄的代碼實現必定不同; 但是每個英雄的技能都是Q、W ...
  • 上面這段代碼是書上關於Nio具體工作過程的代碼示例。其工作過程可以具體闡述如下: 其中有兩個關鍵的類:Channel和Selector,它們是NIO中的核心概念。其中Channel可類比為交通工具,而且是具體的交通工具,例如:汽車,自行車。而Selector則可以類比為車輛調度系統,負責車輛運行狀況 ...
  • image.png 配置python 2.7 bs4 requests 安裝 用pip進行安裝 sudo pip install bs4 sudo pip install requests 簡要說明一下bs4的使用因為是爬取網頁 所以就介紹find 跟find_all find跟find_all的不 ...
  • 有一定編碼經驗的人,不知不覺就能掌握一些常用的設計模式。 設計模式於我的感悟就是,編碼的套路,解決特定問題的最佳實踐。正如打LOL一樣,遇到不同的戰局,採取不能的策略。 新手剛瞭解設計模式中抽象的概念時容易一臉茫然(沒有遇到具體的應用場景確實也難以掌握),而老手往往駕輕就熟。 其實各行各業很多方面的 ...
  • 最近做了幾個簡單的網頁,發現定位真的非常好用,下麵我來總結下定位的使用方法。 定位:position 首先我們一起來看看定位的基本思想:它允許你定義的元素框相對於其正常位置應該出現的位置,或者相對於父元素,另一個元素甚至瀏覽器視窗本身的位置。 定位:絕對定位,相對定位,固定定位。 ①position ...
  • 前言 HTML5 中提供的文件API在前端中有著豐富的應用,上傳、下載、讀取內容等在日常的交互中很常見。而且在各個瀏覽器的相容也比較好,包括移動端,除了 IE 只支持 IE10 以上的版本。想要更好地掌握好操作文件的功能,先要熟悉每個API。 原文作者:林鑫,作者博客:https://github. ...
  • 前面的話 按鈕式下拉菜單僅從外觀上看,和下拉菜單效果基本上是一樣的。不同的是普通的下拉菜單是block元素,而按鈕式下拉菜單是inline-block元素。本文將詳細介紹Bootstrap按鈕式下拉菜單 概述 按鈕式下拉菜單其實就是普通的下拉菜單,唯一不同的是外部容器“div.dropdown”換成 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...