Bootstarp學習(十三)標籤,bootstarp學習標籤

來源:互聯網
上載者:User

Bootstarp學習(十三)標籤,bootstarp學習標籤
標籤

在一些Web頁面中常常會添加一個標籤用來告訴使用者一些額外的資訊,比如說在導航上添加了一個新導航項,可能就會加一個“new”標籤,來告訴使用者。這是新添加的導航項。如所示:

那麼在Bootstrap架構中特意將這樣的效果提取出來成為一個標籤組件,並且以“.label”樣式來實現高亮顯示。

既然他是一個獨立的組件,當然在不同的版本下有不同的檔案:

      LESS版本:對應的源檔案label.less

      Sass版本:對應的源檔案_label.scss

      編譯後版本:bootstrap.css檔案第4261行~第4327行

使用原理:

使用方法很簡單,你可以在使用span這樣的行內標籤:

<h3>Example heading <span class="label label-default">New</span></h3>

運行效果見右側結果視窗。

實現原理:

/*bootstrap.css檔案第4261行~第4272行*/

.label {display: inline;padding: .2em .6em .3em;font-size: 75%;font-weight: bold;line-height: 1;color: #fff;text-align: center;white-space: nowrap;vertical-align: baseline;border-radius: .25em;}

如果使用的是a標籤元素來製作的話,為了讓其更美觀,在hover狀態去掉底線之類:

/*bootstrap.css檔案第4273行~4278行*/

.label[href]:hover,.label[href]:focus {color: #fff;text-decoration: none;cursor: pointer;}

有的時候標籤內沒有內容的時候,可以藉助CSS3的:empty虛擬元素將其隱藏:

.label:empty {display: none;}

顏色樣式設定:

和按鈕元素button類似,label樣式也提供了多種顏色:

     label-deafult:預設標籤,深灰色

     label-primary:主要標籤,深藍色

     label-success:成功標籤,綠色

     label-in:資訊標籤,淺藍色

     label-warning:警告標籤,橙色

     label-danger:錯誤標籤,紅色

主要是通過這幾個類名來修改背景顏色和文本顏色:

<span class="label label-default">預設標籤</span><span class="label label-primary">主要標籤</span><span class="label label-success">成功標籤</span><span class="label label-info">資訊標籤</span><span class="label label-warning">警告標籤</span><span class="label label-danger">錯誤標籤</span>

運行效果見右側結果視窗。

顏色實現原理:

/*bootstrap.css檔案第4286行~第4237行*/

.label-default {background-color: #999;}.label-default[href]:hover,.label-default[href]:focus {background-color: #808080;}.label-primary {background-color: #428bca;}.label-primary[href]:hover,.label-primary[href]:focus {background-color: #3071a9;}.label-success {background-color: #5cb85c;}.label-success[href]:hover,.label-success[href]:focus {background-color: #449d44;}.label-info {background-color: #5bc0de;}.label-info[href]:hover,.label-info[href]:focus {background-color: #31b0d5;}.label-warning {background-color: #f0ad4e;}.label-warning[href]:hover,.label-warning[href]:focus {background-color: #ec971f;}.label-danger {background-color: #d9534f;}.label-danger[href]:hover,.label-danger[href]:focus {background-color: #c9302c;}
<!--代碼--><h3>Example heading <span class="label label-default">New</span></h3>  <!--代碼--><span class="label label-default">預設標籤</span><span class="label label-primary">主要標籤</span><span class="label label-success">成功標籤</span><span class="label label-info">資訊標籤</span><span class="label label-warning">警告標籤</span><span class="label label-danger">錯誤標籤</span> 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.