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

Support :root pseudo-class selector and rem unit as expected #240

Merged
merged 5 commits into from
May 9, 2020

Conversation

yhatt
Copy link
Member

@yhatt yhatt commented May 6, 2020

Recognize :root pseudo-class selector and rem unit and transform styles while rendering, to reflect the view that the author expected by CSS theme.

  • :root will be transformed into section.
  • font-size declarations containing in the rule targeted into section (includes transformed from :root) will assign to section container as --marpit-root-font-size CSS custom property.
  • XXrem unit in all CSS declarations will be transformed into calc(var(--marpit-root-font-size, 1rem) * XX). Thus, rem within the context of Marpit will always be indicated a relative size from the root element of the slide (<section>).
:root {
  font-size: 16px;
}
h1 {
  font-size: 2rem;
}

The above theme CSS will transform into this CSS in the default constructor options:

div.marpit > section {
  font-size: 16px;
}
div.marpit > section {
  --marpit-root-font-size: 16px;
}
div.marpit > section h1 {
  font-size: calc(var(--marpit-root-font-size, 1rem) * 2);
}

The theme author can use :root selector and rem unit with a familiar way, and don't have to take care of the root font size of the integrated service. And developer using Marpit also doesn't have to take care of the font size in the root and the Marpit container.

Resolves #232.

ToDo

  • Add test cases

@yhatt yhatt changed the title Support :root pseudo-class selector and rem unit Support :root pseudo-class selector and rem unit as expected May 6, 2020
@yhatt yhatt marked this pull request as ready for review May 7, 2020 13:42
yhatt added 2 commits May 9, 2020 15:14
Add the section about :root pseudo-class selector, and makes minor
changes in some sections.
@yhatt yhatt merged commit ea35c60 into master May 9, 2020
@yhatt yhatt deleted the root-selector-and-rem-unit branch May 9, 2020 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace :root selector in CSS theme into section
1 participant