Darkening an image with CSS (In any shape)

后端 未结 5 724
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 18:27

So I have seen quite a few ways to darken images with CSS, including ones with rounded corners, but my problem is different.

Let\'s say I have an .png image that loo

5条回答
  •  旧时难觅i
    2020-12-30 19:10

    Webkit only solution

    Quick solution, relies on the -webkit-mask-image property. -webkit-mask-image sets a mask image for an element.

    There are a few gotchas with this method:

    • Obviously, only works in Webkit browsers
    • Requires an additional wrapper to apply the :after psuedo-element (IMG tags can't have :before/:after pseudo elements, grr)
    • Because there's an additional wrapper, I'm not sure how to use the attr(…) CSS function to get the IMG tag URL, so it's hard-coded into the CSS separately.

    If you can look past those issues, this might be a possible solution. SVG filters will be even more flexible, and Canvas solutions will be even more flexible and have a wider range of support (SVG doesn't have Android 2.x support).

提交回复
热议问题