html - 带有 CSS 覆盖溢出的 CSS 圆形图像

标签 html css

我有一张图片,高度和宽度均为 500 像素。我使用 border-radius 使它成为一个圆形图像。我还有一个纯色背景色,我使用 border-radius 使其也成为一个圆圈。

我正在尝试通过降低图像的不透明度来在悬停时创建叠加层,让背景图像透过。我基本上可以正常工作,尽管在实际图像的底部显示背景图像有大约 1px 的重叠。

enter image description here

片段:

 .image-wrapper {
	    width: 100%;
	    height: 100%;
	    background-color: #000;
	    border-radius: 50%;
	    margin: 0;
        padding: 0;
    }
    img {
	    width: 100%;
	    height: 100%;
	    margin: 0;
        padding: 0;
    }
<div class="image-wrapper">
		<img class="testing red" src="img.jpg">
	</div>

正如您从示例中看到的那样,在任何悬停之前,图像底部大约显示一个像素的背景。

最佳答案

我认为这里的问题是 img 默认有 display: inline。 您可以通过在 CSS 中将 img 设置为 display: block 来解决此问题

.image-wrapper {
    width: 100%;
    height: 100%;
    background-color: #000;
    border-radius: 50%;
    margin: 0;
    padding: 0;
}
img {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    display: block;
    border-radius: 50%;
}
<div class="image-wrapper">
  <img class="testing red" src="http://lorempixel.com/400/400">
</div>

关于html - 带有 CSS 覆盖溢出的 CSS 圆形图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44816999/

相关文章:

php - 访问由 while 循环生成的特殊 div

html - 链接在移动模式下不起作用

javascript - 垂直居中垂直文本

jquery - 自定义输入按钮显示所选文件

javascript - 无法让我的 JavaScript 对象出现在单独的列中

html - div 中 ul 和 p 之间的垂直空间

html - 如何更改我的 Mercurial Web 界面方面

javascript - 通过淡入背景图像制作幻灯片

html - 边框没有出现在 IE 中

html - 未对齐的 Twitter Follow 和 Facebook Like 按钮