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

CSS isolation isn't working because the css is added in the wrong order #59186

Closed
1 task done
jbaumflek opened this issue Nov 26, 2024 · 2 comments
Closed
1 task done
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved

Comments

@jbaumflek
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have a series of nested components, both in the same RCL. I have added the outer div where necessary to achieve the css isolation. I have pushed common CSS up to as high a parent component as I can. However, there are times when I want to override the parent component's ::deep styles with the child component's own ::deep style (::deep is required because I'm using a third-party component library). The only reason this doesn't work is that the RCL's css is added randomly, AFAIK. In other words, since with CSS, last one wins, the order in which the components styles get added to my library's generated css file should be ... rankable?
Currently:
<child component's styles> ::deep .style1 {lineheight: 2em !important;} <parent component's styles> ::deep .style1 {lineheight: 1em; }
This results in the parent style being the matched style.

Expected Behavior

I'd like the css builder to build a graph of dependencies and order with child css added after parents. That way the child's overrides will take precedence.
<parent component's styles> ::deep .style1 {lineheight: 1;} <child component's styles> ::deep .style1 {lineheight: 2em !important; }

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

8

Anything else?

This is the child component. Note inclusion line in .bundle.scp.css file.
Image
I added it with two paths since the first wasn't working.

This is the parent component's css selector
Image
Since this is coming in later in the css, the parent component's styling is applied.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Nov 26, 2024
@javiercn
Copy link
Member

javiercn commented Nov 27, 2024

@jbaumflek thanks for contacting us.

If you need to beat specificity or very precisely control it, we recommend you rely on cascade layers https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Cascade_layers

As for the "random" aspect of the imported files, they aren't random, there's a deterministic order applied to them.

Finally, dotnet/razor#7606 is likely to help here.

@javiercn javiercn added question ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. labels Nov 27, 2024
@jbaumflek
Copy link
Author

Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved
Projects
None yet
Development

No branches or pull requests

2 participants