html - 使用 CSS 过渡来更改元素位置

标签 html css

我想更改悬停时 div 的位置,我可以使用以下代码来实现。当我将鼠标悬停在 .box 上的任意位置时,.info 的位置会从下到上更改。

我想用过渡效果改变它的位置,让它看起来像是向上移动,而不是快速向上出现。仅使用 CSS 可以完成吗?

我正在尝试使用转换属性,但无法使其工作。这是我的代码:

HTML:

<div class="box">
    <div class="img"><img src="http://i.imgur.com/SGw04SV.jpg" /></div>
    <div class="info">
        <div class="title">Hello world</div>
        <div class="more">more stuff</div>
    </div>    
</div>

CSS:

.box{
    width: 400px;
    height: 400px;
    overflow: hidden;
    position: relative;
    -moz-transition: all 0.5s ease-in-out;
        transition: all 0.5s ease-in-out;
}

.info{
    position: absolute;
    bottom: 0;
    
}

.box:hover .info{
    top: 0;
}

演示: https://jsfiddle.net/fXXsS/

最佳答案

here是一个可能的答案

HTML:

    <div class="box">
        <img src="http://i.imgur.com/SGw04SV.jpg"/>
        <div class="info">
            <div class="title">Hello world</div>
            <div class="more">more stuff</div>
        </div>
    </div>

CSS:

    .box {
      position: relative;
    }
    .box img {
      width: 400px;
      height: 400px;
      overflow: hidden;
    }
    .info {
      position: absolute;
      top: 0;
      margin-top: 400px;
    }
    
    .box:hover .info {
      margin-top: 0;
      -moz-transition: all 0.5s ease-in-out;
      transition: all 0.5s ease-in-out;
    }

关于html - 使用 CSS 过渡来更改元素位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18794215/

相关文章:

javascript - 列表元素像新闻贴纸一样垂直滚动

html - 如何使带有标签的下拉箭头可点击

html - 列表中的 float 元素

javascript - 如何让我的暗模式开关在每次点击时都能正常工作?

jquery - 当我从 Dreamweaver 进行浏览器预览时,javascript 行为不起作用,

带边框的 HTML 样式

JQuery 删除验证

javascript - 如何使用javascript检查图像url是否为404

CSS 悬停覆盖在重叠到 div 上的箭头上

html - 允许基于 "overflow: hidden"的导航中的图像溢出