【问题标题】:How do you make an IMAGE move independent of the elements around it using CSS3 Transition?如何使用 CSS3 过渡使 IMAGE 移动独立于其周围的元素?
【发布时间】:2012-06-24 02:53:12
【问题描述】:

<div> 悬停在上面时,我正在尝试使用 CSS3 过渡使 <div> 中的图像向上移动 10 个像素。它在 Firefox 中运行良好,但是当我在 Chrome 和 Safari 中查看它时,<h3><p> 元素上下抖动了一下。

这是我的 CSS:

.feature-table #box {
    width: 325px;
    height: 372px;
    margin-right: 20px;
    float: left;
}

.feature-table a {
    display: block;
    width: 325px;
    height: 372px;
}

.feature-table a img {
    display: block;
    margin-left: auto;
    margin-right: auto;
    padding-top: 54px;
    padding-bottom: 40px;
    -moz-transition: all 0.3s linear;
    -webkit-transition: all 0.3s linear;
    transition: all 0.3s linear;
}

.feature-table a: hover img {
    padding-top: 44px;
    padding-bottom: 50px;
}

.feature-table a h3 {
    font-family: 'GothamBold', sans-serif;
    font-size: 30px;
    color: #3d3d3d;
    text-align: center;
    text-decoration: none;
    margin: 0;
    padding: 0 25px;
}

.feature-table a: hover h3 {
    color: #f6ce4f;
}

.feature-table a {
    text-decoration: none;
}

.feature-table p {
    font-family: 'GothamLight', sans-serif;
    font-size: 14.5px;
    color: #949494;
    text-align: center;
    padding: 10px 28px;
}

.feature-table .caret {
    border-top: 5px solid #fff;
    border-bottom: 5px solid #fff;
    border-left: 5px solid #ffc235;
    content: "";
    display: inline-block;
    height: 0;
    width: 0;
    margin-left: 10px;
}

这是我的 HTML 的一部分:

<div id="box">
    <a href="#">
        <img src="images/payment_icon.png" width="114" height="115" border="0" />
        <h3>Customizable Campaign Pages</h3>
        <p>Tell your story with images, video, rich text and social updates<b class="caret"></b></p>
    </a>
</div>

有什么想法吗?

【问题讨论】:

    标签: html css css-transitions


    【解决方案1】:

    这可能是一个性能问题,因为您正在为影响当前布局的 2 个不同属性设置动画。
    理想的解决方案是使用不影响其他元素的特定道具。在您的情况下,这可以通过 top 属性来完成,在将图像的位置设置为 relative 之后:

    a img{
        position : relative;
        top : 0;
    }
    a:hover img{
        top : -4px;
    }
    

    这是一个工作演示:http://jsfiddle.net/p7Lxz/

    【讨论】:

    • 我最终为这个元素添加了 inline-block。 .feature-table a { display: inline-block;宽度:325px;高度:372px;然后使 img 元素位置绝对,它工作完美!
    猜你喜欢
    • 2013-08-24
    • 1970-01-01
    • 2013-09-17
    • 2013-05-21
    • 2019-03-26
    • 1970-01-01
    • 2012-05-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多