• 军军小站|张军博客
    • 首页
    • 编程技术
      • Java
      • C++
      • C#
      • Python
      • Android
      • IOS
      • ASP.NET
      • Hive
      • Hadoop
      • Hbase
      • Spark
      • redis
      • PHP
      • Jquery
      • Javascript
      • CSS
      • 批处理
    • 系统架构
      • Tomcat
      • Weblogic
    • 数据库相关
      • Oracle
      • SqlServer
      • MySql
      • DB2
      • PostgreSql
      • NoSQL
    • 操作系统
      • Windows
      • Linux
      • VMware
      • Ubuntu
    • 资料下载
      • 工作经验
      • AI人工智能
    • 各行各业
      • 教育资料
      • 金融业务
      • 交易系统
      • 其它
    • 其它
      • 站内视频
      • 军军音乐
      • 网址导航
      • 随言碎语
      • 赚钱工具
    • 云聊
    • 企业官网
    军军小站|张军博客www.zhangjunbk.com
    注册 登录
    欢迎来访张军网站:连续登录【5】天博主自动为您充值【5】积分哦 欢迎来访张军网站:连续登录【5】天博主自动为您充值【5】积分哦 欢迎来访张军网站:连续登录【5】天博主自动为您充值【5】积分哦
    > CSS

    纯CSS打造的Family tree(族谱)

    系统 2019-08-29 23:03:42 2716 0

    Family tree(族谱),也称家谱,用来记录家族世系繁衍辈份关系。本文结合实例,不借助任何js脚本,使用纯CSS打造一个漂亮的Family tree(族谱),也可以应用的企业组织架构图中。

    纯CSS打造的Family tree(族谱)
    查看演示 下载源码

    HTML

    我们使用div#tree来包含整个族谱结构,内部以ul和li元素构建数据源。实际开发中这些族谱数据源可以从数据库中读取,就像得到一个 无限级的分类列表 ,以下是主要的html结构。

              <div class="tree"> 
        <ul> 
            <li> 
                <a href="#">Parent</a> 
                <ul> 
                    <li> 
                        <a href="#">Child</a> 
                        <ul> 
                            <li><a href="#">Grand Child</a></li> 
                        </ul> 
                    </li> 
                    <li> 
                        <a href="#">Child</a> 
                        <ul> 
                            <li><a href="#">Grand Child</a></li> 
                            <li> 
                                <a href="#">Grand Child</a> 
                                <ul> 
                                    <li><a href="#">Great Grand Child</a></li> 
                                    <li><a href="#">Great Grand Child</a></li> 
                                    <li><a href="#">Great Grand Child</a></li> 
                                </ul> 
                            </li> 
                            <li><a href="#">Grand Child</a></li> 
                        </ul> 
                    </li> 
                </ul> 
            </li> 
        </ul> 
    </div> 
            

     

    CSS

    我们使用css中的 :before、:after 两个伪类的content属性来构建元素间的连接线,同时使用了css3实现元素的圆角效果,并加上了鼠标滑上hover效果,这样鼠标滑向族谱中的一个 节点元素,与之相关的后辈元素都会有hover效果,完整的css代码如下:

              .tree ul { 
        padding-top: 20px; position: relative; 
         
        transition: all 0.5s; 
        -webkit-transition: all 0.5s; 
        -moz-transition: all 0.5s; 
    } 
     
    .tree li { 
        float: left; text-align: center; 
        list-style-type: none; 
        position: relative; 
        padding: 20px 5px 0 5px; 
         
        transition: all 0.5s; 
        -webkit-transition: all 0.5s; 
        -moz-transition: all 0.5s; 
    } 
     
    /*We will use ::before and ::after to draw the connectors*/ 
     
    .tree li::before, .tree li::after{ 
        content: ''; 
        position: absolute; top: 0; right: 50%; 
        border-top: 1px solid #ccc; 
        width: 50%; height: 20px; 
    } 
    .tree li::after{ 
        right: auto; left: 50%; 
        border-left: 1px solid #ccc; 
    } 
     
    /*We need to remove left-right connectors from elements without  
    any siblings*/ 
    .tree li:only-child::after, .tree li:only-child::before { 
        display: none; 
    } 
     
    /*Remove space from the top of single children*/ 
    .tree li:only-child{ padding-top: 0;} 
     
    /*Remove left connector from first child and  
    right connector from last child*/ 
    .tree li:first-child::before, .tree li:last-child::after{ 
        border: 0 none; 
    } 
    /*Adding back the vertical connector to the last nodes*/ 
    .tree li:last-child::before{ 
        border-right: 1px solid #ccc; 
        border-radius: 0 5px 0 0; 
        -webkit-border-radius: 0 5px 0 0; 
        -moz-border-radius: 0 5px 0 0; 
    } 
    .tree li:first-child::after{ 
        border-radius: 5px 0 0 0; 
        -webkit-border-radius: 5px 0 0 0; 
        -moz-border-radius: 5px 0 0 0; 
    } 
     
    /*Time to add downward connectors from parents*/ 
    .tree ul ul::before{ 
        content: ''; 
        position: absolute; top: 0; left: 50%; 
        border-left: 1px solid #ccc; 
        width: 0; height: 20px; 
    } 
     
    .tree li a{ 
        border: 1px solid #ccc; 
        padding: 5px 10px; 
        text-decoration: none; 
        color: #666; 
        font-family: arial, verdana, tahoma; 
        font-size: 11px; 
        display: inline-block; 
         
        border-radius: 5px; 
        -webkit-border-radius: 5px; 
        -moz-border-radius: 5px; 
         
        transition: all 0.5s; 
        -webkit-transition: all 0.5s; 
        -moz-transition: all 0.5s; 
    } 
     
    /*Time for some hover effects*/ 
    /*We will apply the hover effect the the lineage of the element also*/ 
    .tree li a:hover, .tree li a:hover+ul li a { 
        background: #c8e4f8; color: #000; border: 1px solid #94a0b4; 
    } 
    /*Connector styles on hover*/ 
    .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 ul::before{ 
        border-color:  #94a0b4; 
    } 
            

     

    要过大年了,祝愿关注Helloweba的朋友新的一年里身体健康,工作顺利!

    原文: http://www.helloweba.com/view-blog-291.html

    纯CSS打造的Family tree(族谱)


    更多文章、技术交流、商务合作、联系博主

    微信扫码或搜索:z360901061

    微信扫一扫加我为好友

    QQ号联系: 360901061

    您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

    【本文对您有帮助就好】元

    您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

    另外一款超棒的响应式布局jQuery插件 – Freeti 仿微软Office 迷你工具条(简易编辑器)
    发表我的评论
    表情
    最新评论 总共0条评论

    站内搜索

    加入交流

    • 1. 手机QQ扫左侧二维码2. 搜Q群:542395358 3. 点击张军网站共享资料群
    • 1. 手机QQ扫左侧二维码2. 搜Q群:922215567 3. 点击java技术沟通群
    • 关注企业微信公众号1.手机微信扫左侧二维码 2. 微信中搜索:上海加盾信息科技有限公司
    • 关注军军小站|张军博客小程序1.手机微信扫左侧二维码 2. 微信搜索小程序:张军博客
    • 关注企业微信小程序1.手机微信扫左侧二维码 2. 微信搜索小程序:上海加盾信息科技有限公司
    • 关注企业钉钉关注企业钉钉
    • 关注企业微信关注企业微信
    • 微信扫一扫添加张军网站微信群微信扫一扫添加张军网站微信群
    • 添加我为微信好友微信扫一扫加我为好友

    标签云

    金融业务 (4)教育资料 (10)Java (901)C++ (86)C# (215)Python (9022)Oracle (911)SqlServer (681)MySql (600)DB2 (33)PostgreSql (23)Tomcat (825)Weblogic (12)Windows (214)Linux (647)VMware (32)Ubuntu (194)ASP.NET (198)Android (681)IOS (75)Hive (45)Hadoop (50)Hbase (9)Spark (4)redis (78)PHP (145)Jquery (174)Javascript (168)NoSQL (6)CSS (127)资料下载 (25)交易系统 (9)java工具类 (32)其它 (7)秕处理 (6)AI技术 (3)

    友情链接

    申请友链

    • 张军博客
    • 上海加盾信息科技有限公司
    • 股票002162悦心健康资金分析
    • 张军博客
    • 张军博客-网址导航
    • 张军java工具类
    • 快手号出售
    • 张军博客-SpringBoot入门

    51链网站

    • 51链首页
    • 51链注册页
    • 广告出售页
    • 友链出租页
    • 软文出售页
    • 友链交换页
    军军小站|张军博客 丨 获取加密软件注册码丨上海加盾信息科技有限公司丨个人简介 丨 © 2020-2030 版权所有丨沪ICP备19026782号-2 | 申请友链 | 站长QQ:360901061