在一些Web頁(yè)面中常常會(huì)添加一個(gè)標(biāo)簽用來(lái)告訴用戶一些額外的信息,比如說(shuō)在導(dǎo)航上添加了一個(gè)新導(dǎo)航項(xiàng),可能就會(huì)加一個(gè)“new”標(biāo)簽,來(lái)告訴用戶。這是新添加的導(dǎo)航項(xiàng)。如下圖所示:
那么在Bootstrap框架中特意將這樣的效果提取出來(lái)成為一個(gè)標(biāo)簽組件,并且以“.label”樣式來(lái)實(shí)現(xiàn)高亮顯示。
既然他是一個(gè)獨(dú)立的組件,當(dāng)然在不同的版本下有不同的文件:
? LESS版本:對(duì)應(yīng)的源文件label.less
? Sass版本:對(duì)應(yīng)的源文件_label.scss
? 編譯后版本:bootstrap.css文件第4261行~第4327行
使用原理:
使用方法很簡(jiǎn)單,你可以在使用span這樣的行內(nèi)標(biāo)簽:
<h3>Example heading <span class="label label-default">New</span></h3>
運(yùn)行效果見右側(cè)結(jié)果窗口。
實(shí)現(xiàn)原理:
/*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標(biāo)簽元素來(lái)制作的話,為了讓其更美觀,在hover狀態(tài)去掉下劃線之類:
/*bootstrap.css文件第4273行~4278行*/
.label[href]:hover, .label[href]:focus { color: #fff; text-decoration: none; cursor: pointer; }
有的時(shí)候標(biāo)簽內(nèi)沒有內(nèi)容的時(shí)候,可以借助CSS3的:empty偽元素將其隱藏:
.label:empty { display: none; }
顏色樣式設(shè)置:
和按鈕元素button類似,label樣式也提供了多種顏色:
? label-deafult:默認(rèn)標(biāo)簽,深灰色
? label-primary:主要標(biāo)簽,深藍(lán)色
? label-success:成功標(biāo)簽,綠色
? label-info:信息標(biāo)簽,淺藍(lán)色
? label-warning:警告標(biāo)簽,橙色
? label-danger:錯(cuò)誤標(biāo)簽,紅色
主要是通過(guò)這幾個(gè)類名來(lái)修改背景顏色和文本顏色:
<span class="label label-default">默認(rèn)標(biāo)簽</span> <span class="label label-primary">主要標(biāo)簽</span> <span class="label label-success">成功標(biāo)簽</span> <span class="label label-info">信息標(biāo)簽</span> <span class="label label-warning">警告標(biāo)簽</span> <span class="label label-danger">錯(cuò)誤標(biāo)簽</span>
運(yùn)行效果見右側(cè)結(jié)果窗口。
顏色實(shí)現(xiàn)原理:
/*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; }
請(qǐng)驗(yàn)證,完成請(qǐng)求
由于請(qǐng)求次數(shù)過(guò)多,請(qǐng)先驗(yàn)證,完成再次請(qǐng)求
打開微信掃碼自動(dòng)綁定
綁定后可得到
使用 Ctrl+D 可將課程添加到書簽
舉報(bào)