This question already has answers here:
BoxShadow: inset on img tag
                                
                                    (3个答案)
                                
                        
                                去年关闭。
            
                    
我只是想在行内图片标签上添加模糊角,因此无法正常工作。

我希望内嵌图像标签为我们提供background图像标签的样式,如下所示,该怎么做?



.test {
  background: url(http://via.placeholder.com/350x150) left top no-repeat;
  box-shadow: 25px 25px 50px 0 white inset, -25px -25px 50px 0 white inset;
  width: 350px;
  height: 150px;
}

img {
  box-shadow: 25px 25px 50px 0 white inset, -25px -25px 50px 0 white inset;
  width: 350px;
  height: 150px;
}

<img src="http://via.placeholder.com/350x150" class="img-fluid" alt="Responsive image">

<div class="test"></div>

最佳答案

您可以使用一个技巧,创建一个容器,然后在图像上放置一个可以伪造模糊效果的图层。

按照此LINK,我只使用了diva中间值。



工作版本



.test {
  background: url(http://via.placeholder.com/350x150) left top no-repeat;
  box-shadow: 25px 25px 50px 0 white inset, -25px -25px 50px 0 white inset;
  width: 350px;
  height: 150px;
}

.image-container {
  position: relative;
  float: left;
}
.image-container::before {
  position: absolute;
  content: '';
  top: 0; bottom: 0; left: 0; right: 0;
  box-shadow: 25px 25px 50px 0 white inset, -25px -25px 50px 0 white inset;
}
.image-container img {
  float: left;
}

<div class="image-container">
  <img src="http://via.placeholder.com/350x150" class="img-fluid" alt="Responsive image">
</div>
<br style="clear:both" />
<div class="test"></div>

07-26 08:43
查看更多