CSS transition or animate slide up from top:100% to bottom:0

微笑、不失礼 提交于 2019-12-11 04:17:31

问题


The inner div has a variable height depends on the length of the text inside, which is always shorter than the outer div. I'd like the inner overlay div to slide up from top:100% to bottom:0 when the outer div is hovered. My CSS code below does not produce the slide up effect I want. It simply pops up the inner div at the bottom of the outer div.

<div class="outer">
    <div class="inner">This is a content block.</div>
</div>

.outer {
    position:relative;
    background-color:#eee;
    width:150px; height:150px;
    overflow:hidden;
}
.inner {
    position:absolute; z-index:10;
    box-sizing:border-box; width:100%; padding:10px;
    background-color:rgba(0,0,0,0.5); color:#fff;
    left:0; right:0; top:100%; bottom:auto;
    transition:top 300ms, bottom 300ms;
}
.outer:hover .inner {
    top:auto; bottom:0;
}

回答1:


your code cannot work because transition doesn't work from/to auto.

you could set bottom:0 by default and play with transfom, e.g.

.outer {
    position:relative;
    background-color:#eee;
    width:150px; height:150px;
    overflow:hidden;
}
.inner {
    position:absolute; z-index:10;
    box-sizing:border-box; width:100%; padding:10px;
    background-color:rgba(0,0,0,0.5); color:#fff;
    left:0; right:0; bottom:0;
transform: translateY(100%);
    transition: transform 300ms;
}
.outer:hover .inner {
    transform: translateY(0);
}


来源:https://stackoverflow.com/questions/48973523/css-transition-or-animate-slide-up-from-top100-to-bottom0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!