html - 如何将边框半径添加到填充而不是图像

标签 html css

我正在尝试实现悬停效果,悬停时图像周围会出现一个圆圈。我通过在悬停时添加背景颜色和 50% 边框半径来实现此目的。出现圆圈,但图像在悬停时也有边框半径,我不希望发生这种情况。

#nine-dots{
    width: 17x;
    height: 17px;
    padding: 10px;
}

#nine-dots:hover {
    background-color: rgba(211, 211, 211, 0.334);
    border-radius: 50%;
}

之前的图片: enter image description here

后像:enter image description here

最佳答案

您可以使用剪辑路径代替边框半径

img {
  padding: 50px;
}

img:hover {
  background-color: red;
  clip-path: circle(50%);
}
<img src="https://picsum.photos/id/1/150/150">

关于html - 如何将边框半径添加到填充而不是图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74313925/

相关文章:

javascript - contenteditable 不适用于动态生成的元素

javascript - 如何强制 div 元素扩展到页面底部?

html - 如何在不影响 <td> 宽度的情况下更改 <th> 的宽度

javascript - 如何制作比我的更好的从右向左调整大小的 jQuery 搜索框?

html - html 输出中的 xtable thead

html - Bootstrap 网格 [2 项] 在中心

CSS - 背景图像显示在移动设备上看起来与浏览器调整大小时不同

html - Safari 布局与 Firefox 不同

html - 在表格单元格中垂直对齐每个 block

html - 更改视频错误后定位的 div 的边距