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 Variables read-only reflection of some global Sass variables

See original GitHub issue

I tried to search, but turns out searching for “css variables” or even “custom properties” isn’t particularly helpful. In any case I did go through a bunch of issues and didn’t see this mentioned. Thus:

Background: situations where adding Sass to the build pipeline is not feasible or not wanted, but one still wants to use Bootstrap values (e.g. colours, sizes, timings) in custom CSS.

Proposal: to add a :root {} section in the default generated CSS that writes out something like:

:root {
  --blue: $blue;
  --indigo: $indigo;
  --purple: $purple;
  --pink: $pink;
  /* etc */
}

Usage would then look like:

.custom-component {
  box-shadow: var(--dark-gray);
  color: var(--indigo);
}

That would either be directly supported by browsers (except IE, Edge, some mobile browsers) or more likely right now compiled-in by the build tool (e.g. PostCSS plugin postcss-custom-properties). Because this is supported right now in modern / dev-used browsers, it also brings a newish component to live editing via the Inspector.

Compatibility: in the event that someone is already using custom properties named the same as the bootstrap variables, then this would only affect them if the bootstrap ones come after their own (otherwise the cascade would take care of it). Apart from that, I don’t see any other compatibility problems, but I might have overlooked some.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
mdocommented, Aug 15, 2017

Tried a PR over at #23446.

1reaction
RehanSaeedcommented, Nov 24, 2017

Could you use this to dynamically change the primary and secondary colours using JavaScript? Something like this:

document.documentElement.style.setProperty('--primary', 'purple');

As far as I can see, the variables are not used anywhere.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Variables - Sass
CSS variables can have different values for different elements, but Sass variables only ... Variables declared at the top level of a stylesheet...
Read more >
A Complete Guide To CSS Variables [With Examples]
In this guide, we delve deeper into what CSS variables are and how to use them to create beautiful responsive websites, along with...
Read more >
Theming: CSS Variables in SCSS - BCodes
renaming variables requires a search-and-replace across the project. Variable declarations. Lets put together a basic CSS theme, with light and ...
Read more >
A Complete Guide to Custom Properties | CSS-Tricks
Everything important and useful to know about CSS Custom Properties. Like that they are often referred to as "CSS Variables" but that's not ......
Read more >
Untitled
Sass is an extension of CSS3, adding nested rules, variables, mixins, ... Any attempt to modify a Readonly variable throws an exception.
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