Skip to content

[css-env-1] Clarify how variables can be detected #2732

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

Open
ghost opened this issue Jun 1, 2018 · 3 comments
Open

[css-env-1] Clarify how variables can be detected #2732

ghost opened this issue Jun 1, 2018 · 3 comments

Comments

@ghost
Copy link

ghost commented Jun 1, 2018

For variables exposed through the user agent (e.g. display cutout) it would be good to have some way of detecting whether an env() variable is available.

Two possible ways we could do this:

@fantasai fantasai added the css-variables-1 Current Work label Jun 8, 2018
@heycam heycam added css-env-1 and removed css-variables-1 Current Work labels Jul 6, 2018
@benfrain
Copy link

These values have been in devices for nearly two years now and other than UA sniffing combined with screen measurement we don't have any means at our disposal to read in the values.

Something like this would be most welcome:

getComputedStyle(element).getPropertyValue(env(safe-area-inset-top));

Is there any progress on exposing these values to script?

@emilio
Copy link
Collaborator

emilio commented Aug 27, 2019

other than UA sniffing combined with screen measurement we don't have any means at our disposal to read in the values.

Wait, why does:

div.style.width = "env(safe-area-inset-top)";
getComputedStyle(div).width

not work?

@benfrain
Copy link

Hi,

That results in this:

<div style="width: env(safe-area-inset-top);"></div>

However, one of the specification authors came through with the solution to this (for my scenario at least):

CSS:

:root {
    --sat: env(safe-area-inset-top);
    --sar: env(safe-area-inset-right);
    --sab: env(safe-area-inset-bottom);
    --sal: env(safe-area-inset-left);
}

JS:

getComputedStyle(document.documentElement).getPropertyValue("--sat")

Full info: https://benfrain.com/how-to-get-the-value-of-phone-notches-environment-variables-env-in-javascript-from-css/

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

4 participants