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

3

8

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

Sportscast answered 28/5, 2015 at 13:42 Comment(2)
Seems similar to #10247755. Just change the .animate.move in that fiddle to be animate.move { bottom: 100%; margin-top: -100px; /*.animate width*/ } Not exactly what your looking for but might send you in the right directionBedrail
Not without changing the document flow by using absolute positioning.Interjection
C
15

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.

Corie answered 28/5, 2015 at 13:55 Comment(0)
G
6

checkout the fiddle https://jsfiddle.net/8paj437a/2/

I set position:absolute to the #appear div. and bottom:0; so it will take height from bottom.

And to keep it intact from top. I placed it within a container and give position relative to the container.

HTML

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

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

CSS

.container {
    width: 308px;
    height:331px;
    position:relative;
}
#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;
    position:absolute;
    left:0;
    bottom:0;
}
.show:hover + .container #appear, .container #appear:hover {
    height: 331px;
}
Gospel answered 28/5, 2015 at 13:51 Comment(0)
E
-1

By default, height transition works from top to bottom. But you can make it work from bottom to top with a very simple trick. All you need is to rotate the div to 180 degrees. This will rotate the transition direction as well. Try this css on your div.

transform: rotate(180deg);
Eonism answered 16/3, 2022 at 23:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.