純css實現樹形結構方法教程

來源:互聯網
上載者:User
本文主要介紹了純css實現樹形結構的範例程式碼的相關資料,使用CSS和HTML就可以將一個多級無序列表的節點展現成樹狀結構,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧,希望能協助到大家。

純css實現屬性結構

css實現屬性結構的思路是利用偽類實現樹形結構連接線,如果想實現點擊展開和收縮以及複選框效果還得配合js來實現。其實展開和收縮就是一個點擊元素其子項目隱藏和顯示的切換。

html結構


    <ul class="domtree">        <li>            1級菜單            <ul>                <li>2級菜單</li>                <li>                    2級菜單                    <ul>                        <li>3級菜單</li>                        <li>3級菜單</li>                    </ul>                </li>            </ul>        </li>        <li>            1級菜單            <ul>                <li>2級菜單</li>                <li>2級菜單</li>            </ul>        </li>    </ul>

css


        ul.domtree,        ul.domtree ul {            margin: 0;            padding: 0 0 0 2em;        }        ul.domtree li {            list-style: none;            position: relative;        }        ul.domtree>li:first-child:before {            border-style: none none solid none;        }        ul.domtree li:before {            position: absolute;            content: '';            top: -0.01em;            left: -0.7em;            width: 0.5em;            height: 0.615em;            border-style: none none solid solid;            border-width: 0.05em;            border-color: #aaa;        }        ul.domtree li:not(:last-child):after {            position: absolute;            content: '';            top: 0.7em;            left: -0.7em;            bottom: 0;            border-style: none none none solid;            border-width: 0.05em;            border-color: #aaa;        }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.