raashi_me

raashi_me

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

Showing Posts 1 to 3

cenotaph

cenotaph

Browsers, specially chrome cache favicon aggressively.

Try with a different browser and incognito mode after your first visit.

Failing that you might have to inline your svg CSS, sometimes it would ignore the CSS completely.

raashi_me

raashi_me OP

For clearing the cache I tried to reload the page with Empty Cache and Hard Reload in chrome. It still ignores dark theme codes.

cenotaph

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();
— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews