简体   繁体   English

仅在无重复背景图像上应用背景渐变

[英]Apply background gradient only over no-repeat background image

I'm trying to insert a background image to the top-right corner of my element and fade it with a gradient.我正在尝试将背景图像插入元素的右上角并用渐变淡化它。 The problem is that gradient is stretched through whole element and not only over the no-repeat image.问题是梯度是通过整个元素拉伸的,而不仅仅是在无重复图像上。

 .bg { /* manually set size for demostration purposes */ width: 800px; height: 1600px; background-repeat: no-repeat; background-position-x: right; background-color: rgba(66, 66, 66, 1); background-image: linear-gradient(45deg, rgba(66, 66, 66, 1), rgba(66, 66, 66, 0.8)), url("https://img.scryfall.com/cards/art_crop/front/b/d/bd8fa327-dd41-4737-8f19-2cf5eb1f7cdd.jpg?1562933099"); }
 <div class="bg" />

Thanks to this answer I was able to solve my question.感谢这个答案,我能够解决我的问题。 Here is finished snippet.这是完成的片段。

 .bg { /* manually set size for demostration purposes */ width: 800px; height: 600px; position: relative; background-color: #424242; } .image { position: absolute; top: 0; right: 0; width: 75%; } .image:after { content: ""; position: absolute; top: 0; right: 0; width: 100%; height: 100%; display: inline-block; background-image: radial-gradient(ellipse at top 35% right 35%, rgba(66,66,66,0.8) 0%, #424242 70%); } .image img { width: 100%; }
 <div class="bg"> <div class="image"> <img src="https://img.scryfall.com/cards/art_crop/front/b/d/bd8fa327-dd41-4737-8f19-2cf5eb1f7cdd.jpg?1562933099" /> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM