html - 动画div从另一个div中的底部滑动

标签 html css

是否可以使用 CSS 在悬停时让一个 div 从 div 的底部滑动到 div 的 50% 高处,然后我可以在其中放置文本。到目前为止,我的编码如下:

<div id="cell1">
    <div style="box-shadow: 5px 5px 5px #999; background-color: #CCC; height: 395px;">
        <div align="center">Image Here</div>
    </div> 
    <p></p>
    <div style="box-shadow: 5px 5px 5px #999; background-color: #CCC; height: 395px;">Article2</div>
</div>

最佳答案

您可以通过绝对定位要在父容器中滑入的 div,然后将其 max-height 从零过渡到 50%。

Demo Fiddle

HTML

<div>
    <div></div>
</div>

CSS

div {
    position:relative; /* important */
    height:200px; /* can be anything */
    width:200px; /* can be anything */
    background:red; /* not important */
}
div div {
    position:absolute; /* important */
    bottom:0; /* important */
    max-height:0; /* important */
    overflow:hidden; /* important */
    background:blue;  /* not important */
    transition:max-height 250ms ease-in; /* important */
}
div:hover div {
    max-height:50%; /* important */
}

关于html - 动画div从另一个div中的底部滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23606584/

相关文章:

html - 有没有办法在html中修改css div的属性

javascript - 鼠标悬停事件影响列表中所有行中的按钮,而不仅仅是特定按钮

javascript - 从 Javascript 的 3 个类中访问内容值

html - 为边缘设置 CSS 边框颜色

javascript - 在 JavaScript 中添加一个简单的 counter[i] 变量以 append 到 wrapper.append(container);

javascript - 带有所有图标的 iron-iconset svg 文件 Polymer 2.0

css - 当浏览器宽度缩小时,如何使 CSS 向左浮动而不 flex

javascript - 单击图像时,使 CSS 悬停内容保留在图像上

html - 第一列中的元素不会在 flexbox 中正确对齐

html - 如何固定段落的位置