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-variables] way to customize break points by variables #1883

Closed
Jinjiang opened this issue Oct 16, 2017 · 1 comment
Closed

[css-variables] way to customize break points by variables #1883

Jinjiang opened this issue Oct 16, 2017 · 1 comment

Comments

@Jinjiang
Copy link

Jinjiang commented Oct 16, 2017

The background is as: https://stackoverflow.com/questions/40722882/css-native-variables-not-working-in-media-queries discussed.

Though I totally understand. But is there anyway to customize break points of a component outside with web standard but without any pre-processer?
Seems making variables in :root element [1] accessible for media query is the nearest way. But I am not sure about it.

An example:

I want to define a web component named <responsive-columns>. Its scoped style [2] is like:

/* in component */
@media (min-width: var(--break-point-min)) {
  :host > * {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(var(--column-width-min), 1fr);
  }
}

So other developers can use it like:

<html>
<head>
  ...
  <style>
  /* global stylesheet */
  :root {
    --break-point-min: 540px;
    --column-width-min: 200px;
  }
  </style>
</head>
<body>
  <responsive-columns>
    ...
  </responsive-columns>
</body>
</html>

Thanks.

[1] https://drafts.csswg.org/selectors-3/#root-pseudo
[2] https://drafts.csswg.org/css-scoping-1/#selectors

@tabatkins
Copy link
Member

Can't use var() for this, even ones set on :root - you can use the results to change what gets set on :root. ^_^

But the more recently-proposed env() function from Apple, which sets up a guaranteed-global variable that doesn't depend on any element, is usable for this.

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

No branches or pull requests

2 participants