Question

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.

Was it helpful?

Solution

  1. Apply filter: invert(1) in dark mode if your logo is simple enough (in shades of grey).

  2. 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 the invert filter applied. When switching to dark mode (with a cool transition), the inverted logo (one white line of text) is revealed.

  3. Use SVG.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top