Start a new topic

CSS variable for posts' background color

In the current implementation of dark mode, it looks like posts are given the class `bg-black`, and then there's a rule
.bg-black {
  background-color: rgb(0 0 0 / var(--tw-bg-opacity));
} 

As a CSS criminal, it'd be nice if the background color of the current post were a variable that I could reference in my style rules, so I could more easily make crimes that look good in both dark mode and light mode (as well as any future color schemes). I'm imagining something like

article {
  background-color: rgb(var(--color-post-background) / var(--tw-bg-opacity));
}

.bg-black {
  --color-post-background: 0 0 0;
} 

5 people like this idea
1 Comment

Ran into a related issue - there's a `--color-background` CSS variable, but it's only set based on a media query for `prefers-color-scheme: dark` and ignores my actual cohost settings E.g. I have cohost set to use light mode, but my phone has dark mode set at the system level. The color-background` CSS variable ends up being black, even though that doesn't match the actual background color for posts
Login or Signup to post a comment