Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding --css-variables in Anki #78

Closed
badlydrawnrob opened this issue Dec 18, 2023 · 1 comment
Closed

Overriding --css-variables in Anki #78

badlydrawnrob opened this issue Dec 18, 2023 · 1 comment

Comments

@badlydrawnrob
Copy link
Owner

badlydrawnrob commented Dec 18, 2023

Here's how custom properties in the cascade are scoped globally and locally.

  1. Override the --css-variables you want after importing main.css
  2. Make sure the specificity is correct
  3. Compile your css file

So long as the specificity is correct (i.e: you're updating CSS variables on the correct global or local class, such as :root or .selector) simply change the CSS Variables at the end of the main.css document! I don't think that you can change --css-variables to override styles that have used that variable (i.e: var(--css-variable)) — although you may be able to if there's greater specificity. The code below won't work as you might hope:

It's fairly easy to add a class to the main HTML <tag> element to switch between themes. I've tried this kind of setup Anki and it works:

:root {
   /* The highlighting colours */
  --color-code-light-background: #ffffcc;
  --color-code-light-base: #586e75;
  --color-code-light-comment: #93a1a1;
  --color-code-light-error: #93a1a1;
  --color-code-light-highlight: #dc322f;
  --color-code-light-keyword: #859900;
  --color-code-light-lowlight: #268bd2;
  --color-code-light-number: #2aa198;
  --color-code-light-operator: #859900;
  --color-code-light-string: #2aa198;
  --color-code-light-variable: #268bd2;
}

/* They're used here, for example */
code,
kbd,
pre,
samp {
  ...
  background: var(--color-code-light-background);
}

You can override the styles at the bottom of the main.css document like this:

:root {
  --color-code-light-background: blue;  /* Make me blue! */
}

You can even use a variable before it's declared:

p {
  color: var(--new-css-variable);
}

#inner {
  --new-css-variable: green;
}

Other examples:

Before (default --css-variables)

Screenshot 2023-12-03 at 18 55 32

After (changing --css-variables)

Screenshot 2023-12-03 at 18 56 18

Originally posted by @badlydrawnrob in #42 (comment)

@badlydrawnrob
Copy link
Owner Author

Closing this and adding link in other issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant