今天我們來看看css組件效果以及其中比較重要的類,這些類都不難,關(guān)鍵要熟練掌握,搭配使用,靈活運用。關(guān)于前兩篇中,css樣式和布局的文章,大家可以在之前的文章中閱讀。
一、導(dǎo)航組件
自己做了個導(dǎo)航,目前只有一級菜單,下一篇文章中,將給出二級菜單,涉及到j(luò)s的插件,所以這里不在描述。
<!DOCTYPE html> <html lang="zh-CN"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"> <!-- 上述3個meta標簽*必須*放在最前面,任何其他內(nèi)容都*必須*跟隨其后! --><title>二級菜單</title><style> .sideBar-menu{margin:20px auto;width: 180px;} /*重寫鼠標滑過的樣式*/.nav-pills li a:hover { background-color: #337ab7; color: #fff;}</style><link href="css/bootstrap.css" rel="stylesheet"><link href="css/bootstrap.min.css" rel="stylesheet"><link href="css/style.css" rel="stylesheet"><script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script><script src="http://cdn.bootcss.com/bootstrap/3.3.4/js/bootstrap.min.js"></script></head><body><!-- bootstrap制作導(dǎo)航菜單 --><div class="sideBar-menu "> <ul class="nav nav-pills nav-stacked"> <li role="presentation" class="active"><a href="#"><span class=" glyphicon glyphicon-th-large"> </span>首頁</a></li> <li role="presentation" class=""><a href="#"><span class=" glyphicon glyphicon-user"> </span>關(guān)于我</a></li> <li role="presentation" class=""><a href="#"><span class=" glyphicon glyphicon-camera"> </span>那些年</a></li> <li role="presentation" class=""><a href="#"><span class=" glyphicon glyphicon-pencil"> </span>碎碎念</a></li> <li role="presentation" class=""><a href="#"><span class=" glyphicon glyphicon-book"> </span>留言板</a></li> <li role="presentation" class=""><a href="#"><span class=" glyphicon glyphicon-heart"> </span>情感語</a></li> </ul></div></body></html>
效果如下:
導(dǎo)航類需要注意以下幾點:
1:導(dǎo)航組件依賴于nav類。(即使用其它類時,都必須寫上這個類)
2:確保導(dǎo)航組件的可訪問性(添加role屬性)
3:涉及到的類包括nav-tabs ,nav-pills(使導(dǎo)航呈現(xiàn)膠囊狀),nav-stacked(使水平導(dǎo)航變?yōu)樨Q直導(dǎo)航),nav-justified(實現(xiàn)導(dǎo)航均等寬度排列)
4:對于disabled類,添加在導(dǎo)航頁中的鏈接時(包括標簽頁和導(dǎo)航頁),只是使其表面上被禁用(顏色變灰,鼠標形狀改變),實際功能依然還存在。
5:帶下拉菜單的導(dǎo)航使用。
我們來看下列子:可自行貼碼測試,不再截圖。
<!-- 導(dǎo)航依賴于nav類nav-tabs類依賴nav類 --> <ul class="nav nav-tabs"> <li role="presentation" class="active"><a href="#">Home</a></li> ---注意加上role屬性 <li role="presentation" class=""><a href="#">Profile</a></li> <li role="presentation" class=""><a href="#">Messages</a></li> </ul><!--膠囊式標簽頁 豎直排列nav-stacked--> <ul class="nav nav-pills nav-stacked"> <li role="presentation" class="active"><a href="#">Home</a></li> <li role="presentation" class=""><a href="#">Profile</a></li> <li role="presentation" class=""><a href="#">Messages</a></li> </ul> <!--兩端對齊導(dǎo)航nav-justified可實現(xiàn)導(dǎo)航均列對齊--> <ul class="nav nav-tabs nav-justified"> <li role="presentation" class="active"><a href="#">Home</a></li> <li role="presentation" class=""><a href="#">Profile</a></li> <li role="presentation" class=""><a href="#">Messages</a></li> </ul> <br><br>
再來看下帶下拉菜單的導(dǎo)航情況:
<ul class="nav nav-pills"> <li role="presentation" class="dropdown"> <a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false"> Dropdown<span class="caret"></span> </a> <ul class="dropdown-menu"> <li><a href="#">Action</a></li> <li><a href="#">Action 111</a></li> <li><a href="#">Action 222</a></li> <li><a href="#">Action 333</a></li> </ul> </li> <li role="presentation" class="divider"></li> --divider表示添加分隔線,一般都是給空的li或者span進行使用 <li role="presentation" class=""><a href="#">Profile</a></li> <li role="presentation" class=""><a href="#">Messages</a></li> </ul>
其實對于使用下拉菜單類dropdown,基本格式都是像上面這樣,或者你把鏈接a變?yōu)閎utton等之類,靈活運用即可。
二、導(dǎo)航條組件
注意點:
1:導(dǎo)航條即把組件全部橫向排列放置,包裹組件,類似于橫向?qū)Ш降男问?/p>
2:確保可訪問性。使用<nav>標簽或者<div role="navigation">
3:涉及到導(dǎo)航條的類包括:navbar-inverse(實現(xiàn)背景顏色為黑色和文字白色效果),navbar-fixed-top|navbar-fixed-bottom(固定導(dǎo)航條在頂部和底部)
navbar-left|navbar-right(通常給最后一個元素加navbar-right),navbar-text,navbar-link(設(shè)置連接顏色),navbar-btn(對于不包含在form表單里的按鈕,可
使用此類,達到垂直居中的效果),navbar-form(達到垂直對齊效果),navber-brand(設(shè)置品牌圖標),navbar-collapse(折疊)
我們來看下navbar-collapse折疊的效果,代碼如下:
<!-- 導(dǎo)航條 collapsed表示折疊--><nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> --導(dǎo)航條頭部 <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#"> brand </a> </div> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> --折疊欄目 <ul class="nav navbar-nav"> <li class="active"><a href="#">Link <span class="sr-only">current</span></a></li> <li><a href="#">Link</a></li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="#">Action</a></li> <li><a href="#">Another action</a></li> <li><a href="#">Something else here</a></li> <li role="separator" class="divider"></li> <li><a href="#">Separated link</a></li> <li role="separator" class="divider"></li> <li><a href="#">One more separated link</a></li> </ul> </li> </ul> <form class="navbar-form navbar-left" role="search"> <div class="form-group"> <input type="text" class="form-control" placeholder="Search"> </div> <button type="submit" class="btn btn-default">Submit</button> </form> <ul class="nav navbar-nav navbar-right"> <li><a href="#">Link</a></li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="#">Action</a></li> <li><a href="#">Another action</a></li> <li><a href="#">Something else here</a></li> <li role="separator" class="divider"></li> <li><a href="#">Separated link</a></li> </ul> </li> </ul> </div><!-- navbar-collapse 折疊--> </div></nav><!-- button中的三橫 --><div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">Brand</a></div>
實現(xiàn)效果如下:
即當我瀏覽器屏幕縮小時,原先的組件都將變?yōu)楦鷅rand一行的 右邊的折疊行(三橫線)。點擊該三橫按鈕,則組件將顯示出來。
三、分頁組件
注意點:
1:使用類pagination(加pagination-lg類可使其變大)
2:實現(xiàn)翻頁對齊與實現(xiàn)翻頁兩端對齊(前和后分別位于兩端)。
貼碼如下:
<!-- 分頁 類--><nav> <ul class="pagination"> <li> <a href="#" aria-label="Previous"> <span aria-hidden="true">«</span> </a> </li> <li class="active"><a href="#">1</a></li> <li><a href="#">2</a></li> <li><a href="#">3</a></li> <li><a href="#">4</a></li> <li><a href="#">5</a></li> <li><a href="#" aria-label="next"><span aria-hidden="true">»</span></a></li> </ul></nav>
如果實現(xiàn)分頁變大直接加上<ul class="pagination pagination-lg">即可。
實現(xiàn)翻頁效果如下:主要用到pager類
<!--翻頁--><nav> <ul class="pager"> <li class="active"><a href="#">previous</a></li> <li><a href="#">next</a></li> </ul></nav><!--對齊鏈接分居兩端加了previous類和next類--><nav> <ul class="pager"> <li class="previous disabled"><a href="#"><span aria-hidden="true">←</span>older</a></li> <li class="next"><a href="#">newer<span aria-hidden="true">→</span></a></li> </ul></nav>
上面兩個的效果如下:
四、徽章
作用:將信息以醒目的數(shù)字呈現(xiàn)出來。
<!--徽章 --><a href="#">Inbox<span class="badge">42</span></a><button class="btn btn-primary" type="button"> Message<span class="badge">4</span></button>
效果如下:
添加此類badge類,也可配合導(dǎo)航等一起使用。
五、縮略圖組件
配合柵格系統(tǒng)和類thumbnail來一起使用。貼碼如下:可自行測試
<!-- 縮略圖thumbnail --><div class="row"> <div class="col-xs-6 col-md-4"> <div class="thumbnail"> <img src="111.png"> <div class="caption"> <h3>Thumbnail label</h3> <p><a href="#" class="btn btn-primary " role="button">Button</a></p> </div> </div> </div> <!-- 第二個 --> <div class="col-xs-6 col-md-4"> <div class="thumbnail"> <img src="111.png"> <div class="caption"> <h3>Thumbnail label</h3> <p><a href="#" class="btn btn-primary " role="button">Button</a></p> </div> </div> </div> <!-- 第三個 --> <div class="col-xs-6 col-md-4"> <div class="thumbnail"> <img src="111.png"> <div class="caption"> <h3>Thumbnail label</h3> <p><a href="#" class="btn btn-primary " role="button">Button</a></p> </div> </div> </div> </div>
六、可關(guān)閉的警告框
使用類:alert-dismissible和一個button 貼碼如下:
<!-- 為警告框提供關(guān)閉按鈕 --><div class="alert alert-warning alert-dismissible" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="close"> <span aria-hidden="true">×</span> --添加aria-hidden屬性 </button> <strong>warning</strong>better check yourself,you are not looking too good.</div><!-- data-dismiss="alert"為確保在所有設(shè)備上的正確行為 -->
關(guān)于情景色,可自行替換。不再描述。設(shè)置alert-link可設(shè)置與當前警告框相符的顏色。
七、進度條
使用類:progress和實現(xiàn)動畫的進度條
<!-- 進度條 --><div class="progress"> <div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemax="100" aria-valuemin="0" style="width:60%;"> 60% </div></div><!-- 設(shè)置最低寬度 --><div class="progress"> <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="width:80%;">80% </div> </div><div class="progress"> <div class="progress-bar" role="progressbar" aria-valuenow="2" aria-valuemin="0" aria-valuemax="100" style="min-width:2em;">2% </div></div>
實現(xiàn)動畫效果的進度條,條紋的進度條使用progress-bar-striped,實現(xiàn)動畫效果加 active即可。貼碼如下:不再截圖
<!-- 條紋類使用progress-bar-striped --><div class="progress"> <div class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width:100%"> <span class="sr-only">40% complete</span>100% </div></div>
也可結(jié)合情景色,改變進度條條紋的顏色。
八、列表組,輸入組組件
先來看列表組,主要用到list-group類,其次列表項目用list-group-item來寫。貼碼如下:
<!-- 列表組 --><ul class="list-group"> <li class="list-group-item"><span class="badge">3</span>1111</li> <li class="list-group-item"><span class="badge">5</span>2222</li> <li class="list-group-item">3333</li> <li class="list-group-item">4444</li> <li class="list-group-item">5555</li></ul><!-- 鏈接作為列表組 也可添加情景類--><div class="list-group"> <a href="#" class="list-group-item active">2222</a> <a href="#" class="list-group-item disabled">33333</a> <a href="#" class="list-group-item-success">44444</a> <a href="#" class="list-group-item-info">55555</a></div><!-- 按鈕作為列表組,使用div,不能用.btn類 --><div class="list-group"> <button type="button" class="list-group-item list-group-item-warning">1111</button> <button type="button" class="list-group-item-danger">2222</button> <button type="button" class="list-group-item-success">3333</button> <button type="button" class="list-group-item-info">4444</button></div><!--列表組定制內(nèi)容 --><div class="list-group"> <a href="#" class="list-group-item active"> <h4 class="list-group-item-heading">list group item</h4> <p class="list-group-item-text">11111</p> </a> <a href="#" class="list-group-item "> <h4 class="list-group-item-heading">list group item</h4> <p class="list-group-item-text">22222</p> </a></div>
來看看輸入組,使用input-group類,將組件包裹在一起使用。貼碼如下:
<!-- 輸入組 --><div class="input-group"> --組件均包含在inout-group的里面 <span class="input-group-btn"> <button class="btn btn-primary" type="button">Go</button> </span> <input type="text" class="form-control" aria-label="text"></div>
九、響應(yīng)式特性的嵌入內(nèi)容
理解一下什么意思,什么叫嵌入內(nèi)容?如何嵌入呢?又如何響應(yīng)呢?
嵌入:即利用<iframe>、<embed>、<video> 和 <object> 等標簽引入外部文件內(nèi)容。相信html5里的新增的屬性大家都知道.video,radio等
響應(yīng):根據(jù)被嵌入內(nèi)容的外部容器的寬度,自動創(chuàng)建一個固定的比例,從而讓瀏覽器自動確定視頻或 內(nèi)容 的尺寸,能夠在各種設(shè)備上縮放。
如果希望讓最終樣式與其他屬性相匹配,還可以明確地使用一個派生出來的 .embed-responsive-item 類。
貼碼如下:
<div class="embed-responsive embed-responsive-16by9"> <iframe class="embed-responsive-item" src="..."></iframe></div><div class="embed-responsive embed-responsive-4by3"> <iframe class="embed-responsive-item" src="..."></iframe></div>
我們來看看embed-responsive-16by9和embed-responsive-4by3分別代表什么意思。
我們來看一下調(diào)式控制臺:
.embed-responsive-4by3 { ---4代表水平,3代表豎向,即一個縮放比例,即為4:3的比例縮放 padding-bottom: 75%;}..embed-responsive-16by9 { padding-bottom: 56.25%;}
保持縱橫比,width按100%算的話,則為100% * 3/4=75%,此時通過設(shè)置它的padding-botom來設(shè)置它的縱橫比。當你縮放瀏覽器時,始
終保持該縮放比例進行縮放。
如果大家還想深入學(xué)習(xí),可以點擊這里進行學(xué)習(xí),再為大家附3個精彩的專題:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點
疑難解答