0

Dark Mode Stylesheet

 2 years ago
source link: https://soffes.blog/dark-mode-stylesheet
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Dark Mode Stylesheet — Hi, I’m Sam

Dark Mode Stylesheet — Hi, I’m Sam

Hi, I’m Sam

This is my blog. I also have a website thing.

Dark Mode Stylesheet

Posted on September 20, 2019

With iOS 13 coming out yesterday, there are a lot more folks are experiencing system-wide Dark Mode for the first time. As you navigate around the system apps in Dark Mode, it’s really nice to see everything be dark. The moment you open up an app that doesn’t support Dark Mode, it can be really jarring. Websites in Safari are one of the biggest offenders for me. We can fix this though.

I recently made my personal website and blog support a dark theme if the user’s device has dark mode enabled. This is really easy to achieve with a relative new features in CSS, custom properties (aka CSS variables). They are already widely supported too!

Here’s how to define variables:

/* Define variables for Light Mode in this selector */
:root {
  /* Variables must to start with `--` */
  --body-foreground: #111;

  /* You can name these variables whatever you want */
  --body-background: #fff;
}

You can override them in a media query for Dark Mode:

/* This media query matches Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    /* Override the Light Mode values */
    --body-foreground: #eee;
    --body-background: #111;
  }
}

Here’s how to use the variable:

body {
  color: var(--body-foreground);
  background-color: var(--body-background);
}

Now your site will automatically switch colors when the user toggles their system setting. You can try it right now to see it in action on this post.

I think taking the time to adjust your website to support Dark Mode is a really nice touch that someone seeing mostly dark UI will really appreciate when they run across it.

Lost Coast

Posted on August 24, 2019

This week, I hiked the nothern section of the Lost Coast Trail with 3 friends. It’s 24.6 miles from Black Sands Beach to Mattole Beach. We started at the southern end and hiked north.

Twenty-four miles in 3 days doesn’t sound that difficult, but it was actually pretty tough. Almost all of the trail is on sand. Hiking a long distance on sand—especially with the slope of the beach into the ocean—is really though on your feet, ankles, knees, etc. We were all pretty sore by the end. It was super beautiful though. I would absolutely do it again!

If you’re curious, here’s my gear list for this trip.

Continue reading →

© 2006-2022 Sam Soffes


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK