這篇文章將為大家詳細(xì)講解有關(guān)純css怎樣實(shí)現(xiàn)多級(jí)折疊菜單折疊樹效果,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
在易門等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計(jì)、成都網(wǎng)站設(shè)計(jì) 網(wǎng)站設(shè)計(jì)制作按需策劃設(shè)計(jì),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),全網(wǎng)整合營(yíng)銷推廣,成都外貿(mào)網(wǎng)站建設(shè),易門網(wǎng)站建設(shè)費(fèi)用合理。
1、運(yùn)用checkbox的checked值來(lái)判斷下級(jí)欄目是否展開,CSS3的選擇器中提供了:checked 這個(gè)偽類,這個(gè)偽類提供我們,當(dāng)元素?fù)碛衏hecked這個(gè)值的時(shí)候就執(zhí)行你的CSS。
當(dāng)有子菜單時(shí),菜單項(xiàng)右側(cè)有向下的箭頭,當(dāng)收起菜單項(xiàng)時(shí),箭頭朝上。圖片可以自己替換。
2、效果圖
3、代碼片段
<ol class="tree"> <li> <label for="folder1" class="folderOne">澤元框架</label> <input type="checkbox" id="folder1" /> <ol> <li> <label for="subfolder1"class="folderTwo">開發(fā)規(guī)范</label> <input type="checkbox" id="subfolder1" /> <ol> <li class="file folderThree"><a href="#">常見界面錯(cuò)誤舉例</a></li> <li class="file folderThree"><a href="#">關(guān)于發(fā)行報(bào)告對(duì)BUG管理提出…</a></li> <li class="file folderThree"><a href="#">插件內(nèi)部JAVA包命名規(guī)范</a></li> </ol> </li> <li class="file folderTwo"><a href="#">概述</a></li> <li class="file folderTwo"><a href="#">服務(wù)器集群</a></li> <li class="file folderTwo"><a href="#">模板</a></li> <li class="file folderTwo"><a href="#">安全機(jī)制</a></li> </ol> </li> <li> <label for="folder2" class="folderOne" >ZCMS</label> <input type="checkbox" id="folder2" /> <ol> <li class="file folderTwo"><a href="#">實(shí)時(shí)數(shù)據(jù)</a></li> <li> <label for="subfolder2" class="folderTwo">實(shí)時(shí)數(shù)據(jù)</label> <input type="checkbox" id="subfolder2" /> <ol> <li class="file folderThree"><a href="#">實(shí)時(shí)數(shù)據(jù)</a></li> <li class="file folderThree"><a href="#">實(shí)時(shí)數(shù)據(jù)</a></li> <li class="file folderThree"><a href="#">實(shí)時(shí)數(shù)據(jù)</a></li> </ol> </li> </ol> </li> <li> <label for="folder3" class="folderOne">ZAS</label> <input type="checkbox" id="folder3" /> <ol> <li class="file folderTwo"><a href="#">實(shí)時(shí)數(shù)據(jù)</a></li> <li class="file folderTwo"><a href="#">實(shí)時(shí)數(shù)據(jù)</a></li> </ol> </li> <li> <label for="folder4" class="folderOne">ZHTML標(biāo)簽</label> <input type="checkbox" id="folder4"/> <ol> <li class="file folderTwo"><a href="#">實(shí)時(shí)數(shù)據(jù)</a></li> <li class="file folderTwo"><a href="#">實(shí)時(shí)數(shù)據(jù)</a></li> </ol> </li> <li> <label for="folder5" class="folderOne">UI框架API手冊(cè)</label> <input type="checkbox" id="folder5"/> <ol> <li class="file folderTwo"><a href="#">實(shí)時(shí)數(shù)據(jù)</a></li> <li class="file folderTwo"><a href="#">實(shí)時(shí)數(shù)據(jù)</a></li> </ol> </li> </ol> <style type="text/css"> .tree {margin: 0;padding: 0;background-color:#f2f2f2;overflow: hidden;} /*隱藏input*/ .tree li input{position: absolute;left: 0;opacity: 0;z-index: 2;cursor: pointer;height: 1em;width:1em;top: 0;} /*所有菜單項(xiàng)設(shè)置統(tǒng)一樣式*/ .tree li {position: relative;list-style: none;} /*一級(jí)菜單加下邊線*/ .tree>li{border-bottom: 1px solid #d9d9d9;} /*給有子菜單的菜單項(xiàng)添加背景圖標(biāo)*/ .tree li label {max-width:999px;cursor: pointer;display: block;margin:0 0 0 -50px;padding: 15px 10px 15px 70px;background: url(../../images/cp-detail-arrow-b.png) no-repeat right center;background-position:95% 50%;white-space:nowrap;overflow:hidden;text-overflow: ellipsis; } .tree li label:hover,li label:focus{background-color:#a7a7a7;color:#fff;} /*清除所有展開的子菜單的display*/ .tree li input + ol{display: none;} /*當(dāng)input被選中時(shí),給所有展開的子菜單設(shè)置樣式*/ .tree input:checked + ol {padding-left:14px;height: auto;display: block;} .tree input:checked + ol > li { height: auto;} /*末層菜單為A標(biāo)簽,設(shè)置樣式*/ .tree li.file a{margin:0 -10px 0 -50px;padding: 15px 20px 15px 70px;text-decoration:none;display: block;color:#333333;white-space:nowrap;overflow:hidden;text-overflow: ellipsis;} .tree li.file a:hover,li.file a:focus{background-color:#a7a7a7;color:#fff;} /*不同層級(jí)的菜單字體大小不同*/ .tree .folderOne{font-size: 18px;} .tree .folderTwo{font-size:16px;} .tree .folderThree{font-size:14px;} </style> <script type="text/javascript"> $(document).ready(function() { //每個(gè)有子菜單的菜單項(xiàng)添加點(diǎn)擊事件 $(".tree label").click(function(){ //獲取當(dāng)前菜單旁邊input的check狀態(tài) var isChecked = $(this).next("input[type='checkbox']").is(':checked'); //展開和收齊的不同狀態(tài)下更換右側(cè)小圖標(biāo) if(isChecked){ $(this).css( "background-image","url(../images/cp-detail-arrow-b.png)" ); }else{ $(this).css( "background-image","url(../images/cp-detail-arrow-t.png)" ); } }); }); </script>
下面介紹下CSS 菜單折疊
先給大家展示效果圖:
如上,假設(shè)一級(jí)菜單是 div,二級(jí)菜單是 ul。形如:
<div>業(yè)務(wù)管理<span></span></div> <ul> ... <ul> <div class="collapsed">匯總分析<span></span></</div> <ul> ... <ul> <div class="collapsed">>系統(tǒng)管理<span></span></</div> <ul> ... <ul>
當(dāng)菜單展開時(shí),左邊有一個(gè)藍(lán)色的標(biāo)記,右邊是折疊標(biāo)記。
左邊藍(lán)色標(biāo)記自不用表,CSS 設(shè)置 border 即可,右邊利用 CSS 也超方便。
div span { float:right; padding-right:20px; } div span:after { content: "∨" } div.collapsed span:after { content: "∧" }
然后再說(shuō)子菜單的折疊效果,有動(dòng)畫噢:
div.collapsed + ul { height: 0px; transition: height 0.5s ease-out; } div ul { height: 80px; transition: height 0.5s ease-in; }
注意 ul 一定要有 height 的具體值,如果沒有具體指明多少 px,則雖然能折疊,但是沒有動(dòng)畫效果。
最后就是利用 jQuery 或 ezj 切換 className 了,當(dāng)點(diǎn)擊 div 的時(shí)候 toggleClass("collapsed")
。
關(guān)于“純css怎樣實(shí)現(xiàn)多級(jí)折疊菜單折疊樹效果”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
網(wǎng)頁(yè)題目:純css怎樣實(shí)現(xiàn)多級(jí)折疊菜單折疊樹效果
路徑分享:http://aaarwkj.com/article20/jjppjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營(yíng)銷推廣、動(dòng)態(tài)網(wǎng)站、虛擬主機(jī)、服務(wù)器托管、自適應(yīng)網(wǎng)站、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)