raashi_me
Issue with prefers-color-scheme media query
I am trying to use svg favicon
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
and I want to toggle favicon in dark mode browser so my code in svg file looks like
circle {
fill: red;
stroke: yellow;
}
@media (prefers-color-scheme: dark) {
circle {fill: yellow;
stroke: red; }
}
But when I change my browser to dark mode favicon doesn’t toggle.
Can anyone help me with this?
Chrome version : Version 89.0.4389.90
Firefox version: 87.0 (64-bit)
Ubuntu: 16.04
Most Liked
cenotaph
as I said it can ignore the CSS most of the time, I think once the SVG is rendered, it won’t update like other HTML elements. I might be wrong.
I had inlined SVG definitions in my CSS. one for default one for dark mode so I could use a light bulb and crescent moon for them as well as having some nice animation if I wanted.
This simple vanilla JS to store, switch, load them
var btn = document.getElementById("btn-toggle");
btn.addEventListener("click", function () {
localStorage.theme === 'dark' ? white() : dark()
})
function dark() {
localStorage.theme = 'dark';
document.body.classList.add('dark-mode');
btn.classList.add('dark');
}
function white() {
localStorage.theme = 'white';
document.body.classList.remove('dark-mode');
btn.classList.remove('dark');
}
function theme() {
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
dark();
} else {
white();
}
}
theme();
1
Popular in Questions
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database.
Dep...
New
Student & New to elixir. Nice language.
I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work.
Or rather, not char, but a substr...
New
Other popular topics
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
Hi everyone,
One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
Hello guys,
I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New







