Darkening an image with CSS (In any shape)

后端 未结 5 635
没有蜡笔的小新
没有蜡笔的小新 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条回答
  •  醉梦人生
    2020-12-30 18:51

    You could always change the opacity of the image, given the difficulty of any alternatives this might be the best approach.

    CSS:

    .tinted { opacity: 0.8; }
    

    If you're interested in better browser compatability, I suggest reading this:

    http://css-tricks.com/css-transparency-settings-for-all-broswers/

    If you're determined enough you can get this working as far back as IE7 (who knew!)

    Note: As JGonzalezD points out below, this only actually darkens the image if the background colour is generally darker than the image itself. Although this technique may still be useful if you don't specifically want to darken the image, but instead want to highlight it on hover/focus/other state for whatever reason.

提交回复
热议问题