【问题标题】:Zoom effect css3 stretch my image缩放效果 css3 拉伸我的图像
【发布时间】:2016-04-16 22:42:26
【问题描述】:

我想制作这个效果:

悬停时的图像会变暗并稍微放大一点。我有效果,但我的初始图像被拉伸了。我不知道背景图片的大小,只希望在用户悬停时图片放大一点。

.highlight{
    background-size: 100% 100%;
    -moz-transition: background-size 3s ease, background-color 3s ease;
    -webkit-transition: background-size 3s ease, background-color 3s ease;
    transition: background-size 3s ease, background-color 3s ease;
}

.highlight:hover{
    background-size: 120% 120%;
    background-color:rgba(0,0,0,0);
    -moz-transition: background-size 3s ease, background-color 3s ease;
    -webkit-transition: background-size 3s ease, background-color 3s ease;
    transition: background-size 3s ease, background-color 3s ease;
}

.highlight:hover:before{
    content: "";
    display: inline;
    width: 100%;
    height: 100%;
    background-color:rgba(0,0,0,0.7);
    -moz-transition: background-size 3s ease, background-color 3s ease;
    -webkit-transition: background-size 3s ease, background-color 3s ease;
    transition: background-size 3s ease, background-color 3s ease;
}

<div class="col-xs-12 col-sm-12 col-md-6">
<div class="highlight" style="background-image:url(image-url)">
    <div class="content">
        <h3>Text</h3>
        <p class="large">More text text text</a>
    </div>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-6">
<div class="highlight" style="background-image:url(image-url2)">
    <div class="content">
        <h3>Text2</h3>
        <p class="large">More text text text2</a>
    </div>
</div>
</div>

【问题讨论】:

    标签: css zooming


    【解决方案1】:

    这是你要找的吗?

    .highlight{
      position: relative;
      height: 300px;
      background-size: 100%;
      background-position: center top;
      -moz-transition: background-size 3s ease;
      -webkit-transition: background-size 3s ease;
      transition: background-size 3s ease;
    }
    .highlight:hover{
      background-size: 120%;
      background-color:rgba(0,0,0,0);
      -moz-transition: background-size 3s ease;
      -webkit-transition: background-size 3s ease;
      transition: background-size 3s ease;
    }
    
    .highlight:before{
      content: ' ';
      position: absolute;
      left: 0; top: 0;
      right: 0; bottom: 0;
      background-color:rgba(0,0,0,0);
      -moz-transition: background-color 3s ease;
      -webkit-transition: background-color 3s ease;
      transition: background-color 3s ease;
    }
    .highlight:hover:before{
      background-color:rgba(0,0,0,0.7);
      -moz-transition: background-color 3s ease;
      -webkit-transition: background-color 3s ease;
      transition: background-color 3s ease;
    }
    <div class="highlight" style="background-image:url(http://lorempixel.com/1100/700/nature/2/)">
        <div class="content">
            <h3>Text</h3>
            <p class="large">More text text text</p>
        </div>
    </div>

    【讨论】:

    • 几乎完美!我在两个图像中都有这种效果,共享页面宽度的 50%。现在,顶部和底部出现一个“边距”。我将在我的帖子中添加一张图片,以便您查看示例。我认为问题在于 hightligh div 被“col-xs-12 col-sm-12 col-md-6” div 包裹。
    • @user1422434 该边距很可能属于h3,因此如果您将h3 { margin: 0 } 添加到您的CSS 中,它应该会消失。如果没有,您需要在发生这种情况的地方发布一个代码 sn-p,这样我就可以看到它可能是什么
    • 好的,问题是我使用的图片是2200x1400,而你的图片是600*400,如果图片更高可能看起来很漂亮
    • @user1422434 换成这个background-position: center top; 怎么办?
    • 现在看起来很漂亮!我发现一门课程在我的亮点上有一个高度,并导致了市长问题:) 谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-29
    • 2013-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多