html - 悬停时展开背景

标签 html css

我有一个带有背景图片的 div,我想做的是,当我将鼠标悬停在它上面时,背景图片的隐藏部分将显示如下例所示:

This is what I am trying to achieve

我的 jsfiddle 示例:

div.test {
  background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg);
    background-size: cover;
    width: 70px;
    height: 70px;
    background-position: center;
    border-radius: 100%;
    display: inline-block;
    transition: all 1s;
    position: absolute;
    top: 100px;

}

.test:hover{
  transform: scale(1.2);
}

body {
  
  text-align: center;
}
<div class="test">

</div>

如您所见,在我的示例中,图片变大了,我想显示另外 20 像素的图片(不影响边框半径)。

最佳答案

一个 html 元素的例子:

div.test {
    background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg) no-repeat 50% 50%;
    background-size: 140px;
    width: 70px;
    height: 70px;
    background-position: center;
    border-radius: 100%;
    display: inline-block;
    transition: all 1s;
    position: absolute;
    top: 100px;
    transform-origin: center center;
}

.test:hover{
    width: 90px;
    height: 90px;
    margin-left: -10px;
    margin-top: -10px;
}

body {
  
  text-align: center;
}
<div class="test">

</div>

示例 clip-pathshape-inside :

div.test {
    background: url(http://media2.intoday.in/indiatoday/images/Photo_gallery/emraan_012315020812.jpg) no-repeat 50% 50%;
    background-size: cover;
    shape-inside: circle(30% at 50% 50%);
    clip-path: circle(30% at 50% 50%);
    -webkit-clip-path: circle(30% at 50% 50%);
    width: 70px;
    height: 70px;
    background-position: center;
    display: inline-block;
    transition: all 1s;
    position: absolute;
    top: 100px;
    transform-origin: center center;
}

.test:hover{
    shape-inside: circle(50% at 50% 50%);
    clip-path: circle(50% at 50% 50%);
    -webkit-clip-path: circle(50% at 50% 50%);
}

body {
  
  text-align: center;
}
<div class="test">

</div>

关于html - 悬停时展开背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41750301/

相关文章:

javascript - Jquery按钮多次替换图像

javascript - 当用户输入等于当前时间时,如何执行 GET 请求?

html - 提交按钮不会与同一行的其他字段垂直对齐

html - 悬停在多个 div 上

html - SVG圆圈动画问题

asp.net - 修改 CSS 文件以适合我的 asp.net 页面

html - 字体系列未应用于移动设备

html - Bootstrap 导航栏没有响应

html - 在 "〒"中显示 div

html - 无法让 CSS flexbox 正确扩展