Animating an element when hovering on two other element using css

后端 未结 1 878
伪装坚强ぢ
伪装坚强ぢ 2021-01-02 15:24

i am trying to animate a div when hovering on another div. Ihave following code

html

相关标签:
1条回答
  • 2021-01-02 15:54

    You need to wrap the content in the div and use a child selector. Note I gave the larger div an id as well. Here is the css:

    JS Fiddle

    #box {
        height: 100px;
        width: 100px;
        background: red;
        position: absolute;
        transition: all 0.4s ease-in-out;
    }
    #content {
        width: 20px;
        background: green;
        height: 0;
        transition: all 0.4s ease-in-out;
        position: margin-top: -100px;
        margin-left: 50px;
        -webkit-transition: all .8s ease;
        -moz-transition: all .8s ease;
        -ms-transition: all .8s ease;
        -o-transition: all .8s ease;
        transition: all .8s ease;
    }
    #box:hover > #content {
        height: 20px;
    }
    
    0 讨论(0)
提交回复
热议问题