CSS3 vertical tree chart-Use: before AND: after, css3 tree

Source: Internet
Author: User

CSS3 vertical tree chart-Use: before AND: after, css3 tree

For more information, see the video. My own CSS3 practice demo.

[Demo]

[HTML]

<div class="tree">        <ul>            <li>                <a href="#">parent</a>                <ul>                    <li>                        <a href="#">child</a>                        <ul>                            <li>                                <a href="#">Grant child</a>                            </li>                        </ul>                    </li>                    <li>                        <a href="#">child</a>                        <ul>                            <li><a href="#">Grant child</a></li>                            <li>                                <a href="#">Grant child</a>                                <ul>                                    <li><a href="#">Great Grant child</a></li>                                    <li><a href="#">Great Grant child</a></li>                                    <li><a href="#">Great Grant child</a></li>                                </ul>                            </li>                            <li><a href="#">Grant child</a></li>                        </ul>                    </li>                </ul>            </li>        </ul>        </div>

 

[CSS3]

*{
Margin: 0;
Padding: 0;
}
. Tree ul {
Padding-top: 20px;
Position: relative;
Webkit-transition: all 0.5 s;
-Moz-transition: all 0.5 s;
Transition: all. 3 s;
}
. Tree li {
Float: left;
List-style: none;
Text-align: center;
Position: relative;
Padding: 20px 5px 0 5px;
Webkit-transition: all 0.5 s;
-Moz-transition: all 0.5 s;
Transition: all. 3 s;
}
/* Use: before,: after as the branch line */
. Tree li: before,. tree li: after {
Content :"";
Position: absolute;
Top: 0;
Right: 50%;
Width: 50%;
Height: 20px;
Border-top: 1px solid # ccc;
}
. Tree li: after {
Right: auto;
Left: 50%;
Border-left: 1px solid # ccc;
}
. Tree li: first-child: before,. tree li: last-child: after {
Border: 0 none;
}
. Tree li: last-child: before {
Border-right: 1px solid # ccc;
-Webkit-border-radius: 0 10px 0 0;
-Moz-border-radius: 0 10px 0 0;
Border-radius: 0 10px 0 0;
}
. Tree li: first-child: after {
-Webkit-border-radius: 10px 0 0 0;
-Moz-border-radius: 10px 0 0 0;
Border-radius: 10px 0 0 0;
}


/* Delete the branch line with only one branch */
. Tree li: only-child: before,. tree li: only-child: after {
Border: none;
}
. Tree li: only-child {
Padding-top: 0;
}


/* Add a sub-branch with only one branch */
. Tree ul: before {
Content :"";
Position: absolute;
Top: 0;
Left: 50%;
Border-left: 1px solid # ccc;
Width: 0;
Height: 20px;
}
. Tree {
Display: inline-block;
Border: 1px solid # ccc;
Padding: 5px 10px;
Color: #666;
Text-decoration: none;
Padding: 10px;
-Webkit-border-radius: 5px;
-Moz-border-radius: 5px;
Border-radius: 5px;
Webkit-transition: all 0.5 s;
-Moz-transition: all 0.5 s;
Transition: all. 3 s;
}

/* Add selected status */
. Tree li a: hover,. tree li a: hover + ul li {
Background-color: # c8e4f8;
Color: #000;
Border: 1px solid #94a0b4;
}
. Tree li a: hover + ul li: after ,. tree li a: hover + ul li: before ,. tree li a: hover + ul: before ,. tree li a: hover + ul: before {
Border-color: #94a0b4;
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.