dotnet / dotnet/aspnetcore

CSS nesting does not work fully in isolated CSS files

Open
#52,422 15 comments 24 reactions 0 assignees View on GitHub
area-blazor enhancement
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

When using CSS nesting in an isolated CSS file, some scenarios do not work at all and others do not behave as expected.

### Expected Behavior

If the intention is to work as the existing system does, then only the "leaf" nodes of the nested CSS should be given the attribute selector, the parent should never have it. Furthermore if a `::deep` is used, then isolated CSS attributes should not be applied to *any* of a parents children.

### Steps To Reproduce

With a set of classes as the following:

```css
.parent {
& .child-1 {

}

& .child-2 {

}

& .child-3 {

}
}
```
This output will be produced in the `*.styles.css`:
```css
.parent[b-7apb7xee7k] {
& .child-1 {

}

& .child-2[b-7apb7xee7k] {

}

& .child-3[b-7apb7xee7k] {

}
}
```
All rules have the attribute selector except the first child.
When you use `::deep` like so:
```css
::deep .parent {
& ::deep .child-1 {

}

& ::deep .child-2 {

}

& ::deep .child-3 {

}
}
```
You get an output thus:
```css
[b-7apb7xee7k] .parent {
& ::deep .child-1 {

}

&[b-7apb7xee7k] .child-2 {

}

&[b-7apb7xee7k] .child-3 {

}
}
```

### Exceptions (if any)

_No response_

### .NET Version

8.0.100

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the examples in an isolated CSS file and inspect the generated *.styles.css output. Compare the nesting and ::deep cases with the expected behavior described in the issue; done means only leaf nodes receive the attribute selector and ::deep prevents attributes on the parent’s children.

Written by the indexing model from the issue text.

Assessment

Tech stack
css
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.