-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
added api page for CSSNestedDeclaration and the style peroperty and a… #36430
added api page for CSSNestedDeclaration and the style peroperty and a… #36430
Conversation
…dded explanation of The Nested Declaration rule on the nesting page
Preview URLs
Flaws (2)Note! 4 documents with no flaws that don't need to be listed. 🎉 URL:
External URLs (1)URL:
(comment last updated: 2024-11-11 16:00:38) |
Hi Hamish, could you review this PR? |
With `CSSNestedDeclarations` the CSS is is parsed correctly. | ||
|
||
```js | ||
let myRules = document.styleSheets[0].cssRules; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, this really doesn't tell me anything because I don't see what the types are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #36430 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my response #36430 (comment)
What do you think a reader can learn from this? I don't particularly might what you show, but it has to show something related to the API we are demonstrating, and really this does not.
If I had to do this I would either have a live example that shows the structure, or add pseudo code. Assuming the second, then something like.
Consider the following
.foo {
background-color: silver;
@media (screen) {
color: tomato;
}
color: black;
}
This would be parsed into a structure similar to the one shown below. Note that blah blah.
[Note, that I am not sure this is correct - I just copied it from your original. Probably it isn't - ie. I don't think the last declaration is nested]
↳ CSSStyleRule
.style
- background-color: silver
↳ CSSMediaRule
↳ CSSNestedDeclarations
.style (CSSStyleDeclaration, 1) =
- color: tomato
↳ CSSNestedDeclarations
.style (CSSStyleDeclaration, 1) =
- color: black
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is, as this is how the order of the rules are retained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think a reader can learn from this? I don't particularly might what you show, but it has to show something related to the API we are demonstrating, and really this does not.
Still not answered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I would do here is write code that creates this structure. I'd do it for you but your repo is locked for edits. So something like:
This example shows how to construct the following stylesheet using the CSSDOM API.
.foo {
background-color: silver;
@media (screen) {
color: tomato;
}
color: black;
}
[Insert the code here]
Note that in order to preserve the parsing order, all the rules before nesting are handled as top-level CSSRules
, while any top level rules after nesting are represented as CSSNestedDeclarations
.
That's why the color-black
is inside a nested declaration even though it is a top level declaration in the original document.
Note that point at the end that you gave me in the other note - this is relevant to usage of this API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure that this is correct, either.
The CSSNestedDeclarations
API only returns that the there is an object of type CSSNestedDeclarations
which in turn are cssRules
with style
s
https://codepen.io/CodeRedDigital/pen/vYozyrG?editors=0112
Although I believe I has managed to explain this better now
Co-authored-by: Hamish Willee <[email protected]>
Co-authored-by: Hamish Willee <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
↳ CSSNestedDeclarations | ||
.style (CSSStyleDeclaration, 1) = | ||
- color: tomato | ||
↳ CSSNestedDeclarations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this nested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment
All the rules before nesting or at-properties are added at the top-level CSSRules anything after nesting or at-properties are added as nested declarations as that is how the order is preserved. Before CSSNestedDeclarations rules at the same level were hoisted up to the top with other rules whcih changed the order and effected the cascade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's really useful thanks! Reading that I think it is more before and after nesting, and the at-rules is just a form of nesting right?
Anyway, if I can have this misunderstanding others can, so I have added proposals https://github.com/mdn/content/pull/36430/files#r1828495475 , https://github.com/mdn/content/pull/36430/files#r1828504825, #36430 (comment)
Co-authored-by: Hamish Willee <[email protected]>
Co-authored-by: Hamish Willee <[email protected]>
Co-authored-by: Hamish Willee <[email protected]>
Co-authored-by: Hamish Willee <[email protected]>
Co-authored-by: Hamish Willee <[email protected]>
Co-authored-by: Hamish Willee <[email protected]>
Co-authored-by: Hamish Willee <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much @dletorey ! All done.
Description
CSSNestedDeclarations
CSSNestedDeclarations.style
CSSOM
page toCSSNestedDeclarations
pageCSSRule
page toCSSNestedDeclarations
pageCSSNestedDeclarations
on Using CSS NestingMotivation
Related issues and pull requests