简体   繁体   English

我怎样才能用阴影制作这样的背景?

[英]how can i make like this background with shadow?

I have a div which contains an image and overlay:我有一个包含图像和叠加层的 div:

<div class="container">
        <div class="overlay"></div>
        <img src="tablet.png" alt="tablet">
</div>

How can I make an overlay with shadow like如何制作带有阴影的叠加层这个 ? ?

While it surely can be done via CSS or SVG, most likely that shadow is just a background image where the shadow is already drawn.虽然它肯定可以通过 CSS 或 SVG 来完成,但很可能阴影只是已经绘制了阴影的背景图像。

However, here's an example of how you could think of it in css:但是,这里有一个示例,说明您如何在 css 中考虑它:

 .scene { position: relative; width: 200px; height: 200px; background: #60c18b; overflow: hidden; } .object { position: absolute; width: 40px; height: 45px; top: 50%; left: 50%; transform: translate(-50%, -50%); background-image: url(https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Fcdn.onlinewebfonts.com%2Fsvg%2Fimg_121330.png&f=1); background-repeat: no-repeat; background-size: 100% 100%; background-position: top left; } .object:after, .object:before { content: ''; display: block; width: 100%; height: 100px; background: linear-gradient(rgba(0,0,0,0.3), transparent); transform: skew(-45deg, 0deg); transform-origin: top left; position: absolute; } .object:before { transform: translateY(2px) skew(0deg, -45deg); transform-origin: top right; width: 100px; height: 100%; position: absolute; right: 0; background: linear-gradient(to left, rgba(0,0,0,0.3), transparent); }
 <div class="scene"> <div class="object"></div> </div>

Note that this is just for fun, it's not perfect and I wouldn't use this on a production site.请注意,这只是为了好玩,它并不完美,我不会在生产站点上使用它。

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

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