I’m trying to add a dark mode on my website via prefers-color-scheme webkit. However, my logo is all black, while my header is white. On dark mode it should be the other way around. My logo is in PNG and I thought it wouldn’t be a bad idea to somehow upload two logos with different selectors and hide one via CSS on light mode, and the other one on dark mode. My question is: is there any way to do it?
If no, does anyone have any other ideas how could I achieve what I need?
EDIT:
I’m trying to do exactly the same thing as this guy: https://www.youtube.com/watch?v=eY4M7HtP9LA&t
However, his logo is a simple text so he can easily change its color via CSS. Mine is in PNG and I’m not able to do this.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
-
Apply
filter: invert(1)in dark mode if your logo is simple enough (in shades of grey). -
Overlay your dark mode logo on top of your normal logo and change the opacity.
This is what we do. Our logo consists of two lines of text, one of them is black and the other is colored. We have the same logo in two containers overlaid one above the other (position: absolute), but one container is half the height of the logo to only cover the first line of text and it has theinvertfilter applied. When switching to dark mode (with a cool transition), the inverted logo (one white line of text) is revealed. - Use SVG.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0