-
Notifications
You must be signed in to change notification settings - Fork 1.1k
USWDS - Core: Repair normalize.css precedence #4703
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
Conversation
| p { | ||
| @extend %usa-prose-p; | ||
| } |
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.
Copy of code inside @mixin usa-paragraph-style with existing placeholders
| h1, | ||
| h2, | ||
| h3, | ||
| h4, | ||
| h5, | ||
| h6 { | ||
| @extend %usa-prose-heading; | ||
| } | ||
|
|
||
| h1 { | ||
| @include h1; | ||
| } | ||
|
|
||
| h2 { | ||
| @include h2; | ||
| } | ||
|
|
||
| h3 { | ||
| @include h3; | ||
| } | ||
|
|
||
| h4 { | ||
| @include h4; | ||
| } | ||
|
|
||
| h5 { | ||
| @include h5; | ||
| } | ||
|
|
||
| h6 { | ||
| @include h6; | ||
| } |
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.
Copy content of @mixin usa-headings-styles (with existing placeholders)
|
Closing in favor of #4726 |
Description
Closes: #4698
Problem details:
Styles from
normalize.cssare taking precedence over some USWDS global typography styles when either the$theme-global-content-stylesand/or$theme-global-paragraph-stylessetting is set totrue. Becausenormalize.cssis reset CSS, it should not take precedence over any USWDS styles.How this is happening
In limited cases, some root global styles are compiling at the top of the CSS file, above the normalize reset CSS. This appears to happen under the following conditions:
@extendedin anotherHere, the main risk is to root global styles (in this case, the heading and paragraph elements) that do not have the specificity to take precedence over normalize CSS.
Compilation order
To solve this and retain normalize.css as our reset, we must reorder how the CSS compiles root global styles so that reset CSS does not take precedence over USWDS styles.
Proposed solution:
Sass mixins compile differently than placeholders, and replacing the affected placeholders with mixins reorders the root CSS below normalize.
However, using mixins throughout has a pitfall we discovered previously: Using the typeset mixins with
* + &inside caused confusion in the compilation. Please reference the notes in PR 4576 for more details.Placeholders do not struggle with
* + &in the same way, so I have limited the placeholder implementation of%usa-prose-pand%usa-prose-headlineto be only insideusa-prose.scss. This code will compile above normalize in the CSS, but it has the specificity to take precendence.Specificity wins
Now only elements with parent selectors live above normalize:
To reproduce issue:
$theme-global-content-styles: trueThings to check:
Confirm vertical margins
margin-bottom: 0<p>,<button>should havemargin-top: 1emConfirm successul
usa-prosecompilationA successful test will show:
Future solution
In the future, we should look to replace normalize, as it does not appear to be an actively maintained code base.
Additional information
Before you hit Submit, make sure you’ve done whichever of these applies to you:
npm testand make sure the tests for the files you have changed have passed.