如何在悬停时裁剪带有圆角边框的图像

huangapple go评论58阅读模式
英文:

How can I crop an image with a border-radius when hover

问题

当鼠标悬停时,如何裁剪带有56px边框半径的图像?

像这样

如何在悬停时裁剪带有圆角边框的图像

(只是我的,我想要有56px定义的CSS边框)

.image-wrapper {
  width: 200px;
  height: 200px;
}

img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 56px; /* 修改为56px */
  transition: .5s;
}

img:hover {
  /* 在这里添加其他样式以实现悬停效果 */
}
<div class="image-wrapper">
  <img src="https://fujifilm-x.com/wp-content/uploads/2021/01/gfx100s_sample_04_thum-1.jpg">
</div>
英文:

How can I crop a image with a border-radius of 56px when hover?

Like this

如何在悬停时裁剪带有圆角边框的图像

(just mine I want to have a css defined border of 56px)

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

 .image-wrapper {
  width: 200px;
   height: 200px;
 }
 
 img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      border-radius: 50px
      transition: .5s;
    }
    img:hover {
      
    }

<!-- language: lang-html -->

    &lt;div class=&quot;image-wrapper&quot;&gt;
    &lt;img src=&quot;https://fujifilm-x.com/wp-content/uploads/2021/01/gfx100s_sample_04_thum-1.jpg&quot;&gt;
    &lt;/div&gt;

<!-- end snippet -->

答案1

得分: 3

使用 clip-path:

img {
  clip-path: inset(0 round 50px);
  transition: .5s;
}
img:hover {
  /* crop by 10px */
  clip-path: inset(10px round 50px);
}
<img src="https://picsum.photos/id/1074/300/300">
英文:

Use clip-path:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

img {
  clip-path: inset(0 round 50px);
  transition: .5s;
}
img:hover {
  /* crop by 10px */
  clip-path: inset(10px round 50px);
}

<!-- language: lang-html -->

&lt;img src=&quot;https://picsum.photos/id/1074/300/300&quot;&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月15日 06:01:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76477851.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定