純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;        }
相關文章

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.