您可以使用 CSS 为 PNG 内容添加非方形阴影吗?
是否可以对 PNG 内容添加阴影?
不是一个正方形,而是一个物体阴影
作用于 PNG 的非透明内容。
Is it possible to do a drop shadow on the content of a PNG?
Not a square, but an object drop shadow that
acts on the non-transparent content of the PNG.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这绝对是可能的。
使用过滤器示例:
It's definitely possible.
Using filters, sample:
在 CSS 中不可能做到这一点。但是,很可能通过画布来完成此操作,但效率会有些低(因为每次都由客户端处理)并且依赖于 JavaScript。在 PNG 中执行此操作会更容易,并且适用于更多浏览器。
如果您想了解更多信息,请在网上搜索“html canvas Blur”和“html canvas load image”等内容。或者更好的是,使用可以完成这一切的画布阴影功能。
这是一个示例: http://philip.html5.org/demos/canvas/shadows /various.html
context.shadow(Color|OffsetX|OffsetY|Blur)
创建上下文context.drawImage
从 img 标签加载 PNG还有一个好处:
It's not possible to do that in CSS. However, it's quite possible to do it through a canvas, but it will be somewhat inefficient (as it's processed by the client each time) and will be JavaScript dependent. Doing it in the PNG will be easier and will work on more browsers.
If you want more information about it, search the web for things like "html canvas blur" and "html canvas load image". Or better still, use the canvas shadow functionality which can do it all.
Here's an example: http://philip.html5.org/demos/canvas/shadows/various.html
context.shadow(Color|OffsetX|OffsetY|Blur)
as desiredcontext.drawImage
And a bonus:
context.toDataURL
if you want to export to PNG (make a web app which you drop PNGs in and it gives you shadows!)时代如何变迁。现在可以在某些浏览器中,如当前接受的答案所示。
<罢工>
使用CSS不可能做到这一点:
这就是我认为你所要求的。
How times change. It's now possible in some browsers, as shown in the currently accepted answer.
It's not possible to do this using CSS:
That's what I assume you're asking for.
在 CSS 可用之前,您可以尝试我的方法。
我的示例使用这张图片:
因为它具有透明背景并且不是正方形(对于 CSS 的 box-shadow开始行动)。它不是很花哨,但是可以很好地满足这个小而简单的教程。
我采取的下一步是根据上面的图像创建另一张图像,将其放置在原始图像下方。
步骤1.添加模糊:
步骤2。删除了光线和对比度:
所以我有了原始图像和阴影。
接下来,我将把它显示为阴影:
样式:
发挥魔法:
添加一个 div 并设置
attribute class="divOriginal common
" 和另一个class="divShadow common"
。结果应该是:
干杯!
阿迪
Until it will be available to CSS, you can try my approach.
My example uses this picture:
because it has a transparent background and it isn't square (for CSS's box-shadow to get into action). It's not very fancy, but serves this small and simple tutorial fine.
Next step I took was to create another image, based on the one above, to place it under the original.
Step1. Add blur:
Step2. Removed light and contrast:
So I have the original and the shadow.
Next I will display it as if it is a shadow:
Style:
Do the magic:
Add one div and set
attribute class="divOriginal common
" and another one withclass="divShadow common"
.The result should be:
Cheers!
Adi
我根据 Chris Morgan 关于画布的建议为此编写了一个 jQuery 插件。您可以在 GitHub 上找到它:https://github.com/Kukunin/image-shadow
I've wrote a jQuery plugin for this, based on Chris Morgan's suggestion about canvas. You can find it on GitHub here: https://github.com/Kukunin/image-shadow
使用createjs
样本可以在以下位置找到:
JSFiddle
Use createjs
sample can be found at
JSFiddle