css div 从一个位置到另一个位置

标签 css css-transitions

我正在尝试做一个图像悬停效果,其中链接从 top:0 移动到 top:40%。问题是当我悬停图像时,链接直接出现在 top:40% 上。这是我的代码:

<div class="featured">
<div class="img-hover">
<a href=""><i></i></a>
</div>
<img src=""/>
</div>

.featured .img-hover {
width:100%;
float:left;
height:100%;
position:absolute;
display:none;
background:rgba(26, 188, 156, 0.6);
}

.featured:hover .img-hover {
display:block;
}

.featured .img-hover a{
width:50px;
height:50px;
float:left;
position:absolute;
top:0;
font-size:2rem;
line-height: 4rem;
opacity:1;
margin-right:20px;
border-radius:50px;
border:2px solid #fff;
color:#fff;
text-align:center;
transition: all 0.5s ease-out;
-webkit-transition: all 0.5s ease-out;
-moz-transition: all 0.5s ease-out;
-o-transition: all 0.5s ease-out;
}

.featured:hover .img-hover a{
top:40%;
}

最佳答案

您的过渡在 a 标签上,它仅在“.featured .img-hover”级别上效果更好。此外,“display:none”的转换效果不佳。我更新了它以从不透明度 0 过渡到 1,它看起来更好。下面是 JSFiddle 和稍微更新的 CSS。看看并根据需要进行调整。

http://jsfiddle.net/UVjFz/

.featured .img-hover {
    width:100%;
    float:left;
    height:100%;
    position:absolute;
    opacity:0;
    background:rgba(26, 188, 156, 0.6);
}

.featured:hover .img-hover {
    display:block;
}

.featured .img-hover a{
    width:50px;
    height:50px;
    float:left;
    position:absolute;
    top:0;
    font-size:2rem;
    line-height: 4rem;
    opacity:1;
    margin-right:20px;
    border-radius:50px;
    border:2px solid #fff;
    color:#fff;
    text-align:center;
    transition: all 0.5s ease-out;
    -webkit-transition: all 0.5s ease-out;
    -moz-transition: all 0.5s ease-out;
    -o-transition: all 0.5s ease-out;
}

.featured:hover .img-hover a{
    top:40%;
}

.featured:hover .img-hover {
    display:block;
    opacity:1;
}

.featured .img-hover {
    -webkit-transition: all 0.5s ease-out;
    -moz-transition: all 0.5s ease-out;
    -o-transition: all 0.5s ease-out;  
}

关于css div 从一个位置到另一个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21664976/

相关文章:

html - 如何编码这种形式?

html - 字体渲染不流畅

css - 我可以只在悬停时应用 CSS 过渡吗?

javascript - 停止 translate3d 转换

css - IE11 消息栏从底部飞起而不是从顶部缓入

javascript - 使用 JavaScript 启动 CSS-Transition

javascript - 在较小的屏幕上,滑出式选项卡应该贴在 Div 的左侧,无论如何

css - 如何在不使用CSS更改为图像的情况下使文本透明

css - 按比例缩小大图像不会更新主体尺寸

css - 如何防止内容堆积在过渡 div 中?