Re:CSS Only dark mode
by dulvui on Saturday June 24, 2023 @04:40AM
(#36456769)
Original author here. I don't like the idea of using JS on my website and I don't think that it is possible to create a light/dark mode switch with only CSS.
But you are right, most users don't know how to do that.
[ Parent
| on HN ]
Re:CSS Only dark mode
by jiggywiggy on Saturday June 24, 2023 @04:43AM
(#36456782)
Would be perfectly reasonable to use js over this feature.
Yes for sure, but my personal policy is not using JS. Anyway my site doesn't have so many visitors ;-) People come, stay for a few seconds and then leave forever.
Re:CSS Only dark mode
by jiggywiggy on Saturday June 24, 2023 @09:06PM
(#36464248)
Hahah old school hate for js. Very good.
Re:CSS Only dark mode
by FireInsight on Saturday June 24, 2023 @04:47AM
(#36456806)
However, it would probably be possible with very minimal JS a la how Tailwind does it, toggling a .dark class in the body element and setting the dark mode variables and colors there.
But adding onclick and window.open() JS functions is somehow justifiable, over using simple <a> links? Of course, there might be some specific case you are solving here, so it would be very educational to hear this out.
Re:CSS Only dark mode
by danielheath on Saturday June 24, 2023 @04:49AM
(#36456825)
You can! Trick is to use the checkbox:selected hack to apply styles, in addition to the colour-scheme media query.
Re:CSS Only dark mode
by CrimsonRain on Saturday June 24, 2023 @04:51AM
(#36456838)
It is possible; just too convoluted/subpar imo. You can use a checkbox's check/uncheck status. One such codepen from quick google: https://codepen.io/shadowfaxrodeo/pen/JjbzNMz