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

Feature request: Support for cascade layers #205

Open
Jarzka opened this issue Jun 4, 2023 · 3 comments
Open

Feature request: Support for cascade layers #205

Jarzka opened this issue Jun 4, 2023 · 3 comments

Comments

@Jarzka
Copy link

Jarzka commented Jun 4, 2023

Hi

Modern CSS supports cascade layers that are useful for example overriding framework specific styles: https://developer.chrome.com/blog/cascade-layers/

I wonder if there is a support coming for this in Garden? Something like at-layer could be a reasonable way to implement this.

@WorldsEndless
Copy link
Collaborator

WorldsEndless commented Jun 5, 2023 via email

@Jarzka
Copy link
Author

Jarzka commented Jun 5, 2023

Let's say my site uses some 3rd party CSS framework as a base style. In this framework, there is a selector which adds a style for list items with links:

.list > li > a {
  color: red;
}

Now I want to override this style in my application code and turn the color into blue. A simple way to do this would be adding an utility class of blue to the a element and creating the equivalent CSS class selector with Garden. The end result would be:

.blue {
  color: blue;
}

However, if I attach this blue class to my a item, it's still going to have red as a color, because the framework's selector .list > li > a is stronger than my own .blue selector. In order to override the red color, I would need to create a selector which is stronger than the one in the framework, something like .list > li > a.blue (this would also kinda defeat the purpose of the blue utility class, it should work everywhere with a simple class selector).

Cascade layers could make this process much simpler. I could wrap all the framework specific code into "framework" layer like so:

@layer framework {
  .list > li > a {
    color: red;
  }
}

Then I would wrap all my application code into its own "application" layer (i.e. I would use the at-layer rule in Garden), which comes after the "framework" layer like so:

@layer application {
  .blue {
    color: blue;
  }
}

Now my a element turns into blue. The @layer rule creates a new cascading context, which automatically overrides all framework selectors, no matter how strong they are.

@dgb23
Copy link

dgb23 commented Sep 2, 2023

To add to this discussion. Here is a CSS snippet from a project I'm working on. It simply describes the layer hierarchy. Anything defined on a layer to the right will override something in the layer to the left.

@layer reset, globals, layout, components, partials, utilities;

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

No branches or pull requests

3 participants