Search code examples
csstransition

CSS transition (height property) - can't get it to roll from bottom


I use height property to animate my DIV, it appears on hover of another element - it "rolls" from top. Is there a way to rotate the animation, so I would get it to appear from bottom to top?

HTML:

<a href="#" class="show">SHOW IT</a>

<div id="appear">
    <img src="http://data.atria.sk/matmenu/celevyk.jpg" />
</div>

CSS:

#appear {
    width: 308px;
    height: 0px;
    overflow:hidden;
    -webkit-transition: all 0.2s linear;
    -moz-transition: all 0.2s linear;
    -o-transition: all 0.2s linear;
    transition: all 0.2s linear;
}
.show:hover + #appear, #appear:hover {
    height: 331px;
}

JSFiddle


Solution

  • One way to do this without using absolute positioning or altering your markup is to transition a margin-top at the same time as the height. So your CSS might look like:

    html, body { background-color: #dedede; }
    
    #appear {
        width: 308px;
        height: 0px;
        overflow:hidden;
        -webkit-transition: all 0.2s linear;
        -moz-transition: all 0.2s linear;
        -o-transition: all 0.2s linear;
        transition: all 0.2s linear;
        margin-top:331px;
    }
    .show:hover + #appear, #appear:hover {
        margin-top:0;
        height:331px;
    }
    <a href="#" class="show">SHOW IT</a>
    
    <div id="appear">
        <img src="http://data.atria.sk/matmenu/celevyk.jpg" />
    </div>

    Here's also a JSFiddle to demonstrate. (If I've misunderstood your intentions, please tell me.)

    Hope this helps! Let me know if you have any questions.