HTML tree full width hover effect

前端 未结 3 1618
醉话见心
醉话见心 2021-01-16 06:55

I have an html tree which is mostly consisting of nested unordered lists.

I need to create a full width hover effect for each leaf, something similar with windows fi

3条回答
  •  爱一瞬间的悲伤
    2021-01-16 07:54

    I've had the same problem as you, after some trying and testing I came up with this. It allows you to add scrollbars and put the padding on the inner .

    HTML

    • Lorem ipsum dolor sit amet, consectetur adipisicing elit
    • Lorem ipsum dolor sit amet, consectetur adipisicing elit
      • Lorem ipsum dolor sit amet, consectetur adipisicing elit

    CSS

    .tree {
        position:relative;
        display: block;
        overflow: auto;
        border: 1px solid #8B9097;
        background-color: #fff;
        margin-left:200px;
        /*! margin-left: just for testing */
    }
    .tree > div {
        display:block;
        position:absolute;
        min-width:100%;
    }
    .tree * {
        white-space: nowrap;
    }
    .tree ul {
        margin:0;
        list-style-type: none;
        padding-left: 20px;
    }
    .tree li > div {
        position:relative;
        margin-left:-100000px;
        padding-left:100000px;
        border: 1px solid transparent;
        display:block;
    }
    .tree li div:hover {
        background-color: #B6BABF;
        color: #fff;
    }
    .tree li.collapsed > ul {
        display:none;
    }
    
    .tree li.expanded > ul {
        display:inherit;
    }
    

    http://jsfiddle.net/WknDZ/17/

提交回复
热议问题