question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: CSS Custom Properties to make styling more accessible

See original GitHub issue

This solution greatly improves clarity and allows beginners to make basic aesthetic changes without having to search for selectors, go into dev tools, etc. I’ve read the manifesto in the docs, and I think this would be helpful for generating early positive feedback for new users getting their feet wet with programming.

Example: These is currently how we set the colors:

/* main_old.css */
body {
  color: #aaa;
}
.dimmed {
  color: #666;
}
.normal {
  color: #999;
}
.bright {
  color: #fff;
}

With custom properties, we would set the defaults in main.css

/* main.css */
:root {
    --grid-gap: 2rem;
    --color-text-body: #aaa;
    --color-text-bright: #fff;
    --color-text-normal: #999;
    --color-text-dimmed: #666;
}
body {
 color: var(--color-text-body);
} 
.dimmed {
  color: var(--color-text-dimmed);
}
.normal {
  color: var(--color-text-normal);
}
.bright {
  color: var(--color-text-bright);
}

and if a beginner wanted to make adjustments, they could use custom.css.sample (similar to how the sample config is used):

/* custom.css */
:root {
    --grid-gap: 2rem;
    --color-text-body: blue;
    --color-text-bright: #fff;
    --color-text-normal: #999;
    --color-text-dimmed: #666;
}

If it were up to me, I would actually just include a custom.css by default with some comments on how it works, but that’s your call. The custom variable for blue text in custom.css. overrides the defaults (#aaa) set in main.css like so: image

So you can see here that all a beginner would need to do was change --color-text-body: to start personalizing their MM. I plan to include add variables for text sizes and fonts to make it easier to tinker with all the stuff you might want to change. I’m already planning on doing some of this for my own benefit but I thought it might be helpful to the community if I shared the work.

Cheers!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rejascommented, Apr 3, 2021

Yep yep, will save layout changes for later. Not super comfortable with building a startup sequence so I’ll let somebody take that one on. Thanks all 🙂

I think you can ignore that startup sequence idea anyway, right @MichMich ?

1reaction
rejascommented, Apr 2, 2021

I like this idea, especially since I had that planned too (https://github.com/MichMich/MagicMirror/compare/master...rejas:custom_properties) But didnt follow it through with not enough time these days, so I’d be happy to see someone else code it 😉

Anyway, I am in favor of this. Like you wrote, it is easier for beginner to change the looks of MM. Plus it would be nice if Module developers would pick it up for their styles too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Strategy Guide To CSS Custom Properties
To get the most out of them, we might need a strategy for how we write and structure CSS with custom properties.
Read more >
A Complete Guide to Custom Properties | CSS-Tricks
The @property “at-rule” in CSS allows you to declare the type of a custom property, as well its as initial value and whether...
Read more >
Supercharging Your CSS Custom Properties - OutSystems
CSS Variables have a major role on the styling of Web Components, being almost the only way to style a custom element's Shadow...
Read more >
CSS Custom Properties: An In-Depth Beginner's Guide
CSS custom properties aka CSS variables are a practical way to make markup more flexible and less repetitive. Usage and examples right here....
Read more >
CSS Custom Properties (vars) with SASS/SCSS, a practical ...
Sometimes the use of CSS Custom Properties is not a case of taste, but a necessity. It just fits perfectly to build themes, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found