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-cascade] !default declarations proposal #2272

Closed
CyberAP opened this issue Feb 4, 2018 · 5 comments
Closed

[css-cascade] !default declarations proposal #2272

CyberAP opened this issue Feb 4, 2018 · 5 comments

Comments

@CyberAP
Copy link

CyberAP commented Feb 4, 2018

!default declarations, opposite to !important declarations, could set a default property value, if it has not been set yet, or if another !default declaration is more specific. User agent styles should be overridden with !default (of course excluding ones with !important).

Consider this example:

<body class="default-theme new-theme">
  <button>Style me!</button>
</body>
.new-theme button {
  border: thin solid black;
}

button {
  border: 1px dotted grey !default;
}

.default-theme button {
  border: none !default;
}

The button would have a thin solid black border in result. Having the !default declaration possible would make it so much easier to do theming or reset CSS.

@CyberAP CyberAP changed the title [css-cascade] !default declarations [css-cascade] !default declarations proposal Feb 4, 2018
@Loirooriol
Copy link
Contributor

I don't like !important very much, and this would be a similar hack. And I don't think it's necessary, because you should be able to achieve a similar behavior by using selectors with 0 specificity (#1170), e.g.

:is(.default-theme button) {
  border: none; /* default */
}

@SebastianZ
Copy link
Contributor

Just want to point out some implications of using !default vs. :is():

  • !default takes the specificity into account, :is() does not
  • !default applies to individual properties, :is() to the whole rule
  • Both keep the effects of the !important annotation untouched

Sebastian

@fantasai
Copy link
Collaborator

I believe this use case is solved in a much more powerful way by @mirisuzanne's Cascade Layers proposal which is now in CSS Cascade Level 5. :)
https://drafts.csswg.org/css-cascade-5/#layering

@fantasai
Copy link
Collaborator

fantasai commented Mar 13, 2021

@CyberAP Does that work for you? Shall we close this issue, or is there something not addressed?

@CyberAP
Copy link
Author

CyberAP commented Mar 13, 2021

I think this is an excellent proposal and does much better job then the proposed !default declaration. The issue should be resolved now, thanks!

@CyberAP CyberAP closed this as completed Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants