Seeking an elegant, CSS-only method for hiding/showing auto-height content (with transitions)

后端 未结 3 1543
逝去的感伤
逝去的感伤 2020-12-12 19:18

I\'d like a method that uses only CSS transitions, to effectively (and attractively) hide/show content on hover.

The caveat being that I wish to keep dynamic (auto)

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 19:47

    You should use scaleY.

    HTML:

    Here (scaleY(1))

    • Coffee
    • Tea
    • Milk

    CSS:

    ul {
        background-color: #eee;
        transform: scaleY(0);    
        transform-origin: top;
        transition: transform 0.26s ease;
    }
    
    p:hover ~ ul {
        transform: scaleY(1);
    }
    

    I've made a vendor prefixed version of the above code on jsfiddle, http://jsfiddle.net/dotnetCarpenter/PhyQc/9/

提交回复
热议问题