-
Notifications
You must be signed in to change notification settings - Fork 22
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
Can an @apply rule be used inside a custom property bag declaration by the same name? #43
Comments
Within a custom property's value, only So using If you want to build a custom property bag out of multiple other custom property bags at declaration time, use .parent {
--foo: {
color: red;
var(--bar);
};
--bar: {
background-color: white;
};
}
.child {
@apply --foo;
/* gets "color: red; background-color: white;" */
} Merging in a child (like your last example) can be accomplished, but it's a little tricky until we get the ability to refer to the parent's variable value. You'd just write something like: .parent {
--styles: { font-family: monospace; };
}
.child {
--styles: { var(parent --styles); color: red; };
}
.grandchild {
@apply --styles;
/* gets "font-family: monospace; color: red; } */
} This is the same problem as building up an "accumulating" variable for normal use - you need something like To do it today, you instead need to change the variable name as you go down the tree, such as appending a generation counter to the var name, so you're not self-referencing. This is tricky and error-prone, obviously. I'm waiting until variables finish getting implemented and used before doing Variables Level 2 with this ability. |
THAT SAID, I might change the |
For example, imagine inside
<my-element>
you have the following style declaration:I've been experimenting with the
@apply
feature in Polymer and, when composing elements, I quickly found myself wanting to have the composing element set some custom property values yet still allow for parent elements to override them. As far as I can tell, that's not supported (at least not explicitly) in this proposal (Polymer fails when trying this).Conceptually related, it's not clear to me whether custom property bags operate as a merge (like they do on elements) or as an override.
For example, consider the following HTML structure and CSS rules:
Is the text red and monospaced, or is it just red because
--styles
was overriden in.child
?What I suspect is that the declarion is overridden, and if so, that could be an argument in favor of custom pseudo-elements as they could more gracefully (and predictably) handle merging of properties via the cascade.
The text was updated successfully, but these errors were encountered: