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

Utilize container queries instead of media queries #7

Open
westonruter opened this issue Feb 27, 2023 · 1 comment
Open

Utilize container queries instead of media queries #7

westonruter opened this issue Feb 27, 2023 · 1 comment

Comments

@westonruter
Copy link
Collaborator

Now that container queries are generally available (caniuse), I suggest that the following logic be updated to use them instead of media queries:

$class_name = sprintf( 'cls-terminator-%s', md5( $block['attrs']['url'] ) );
$css = '';
foreach ( $block['attrs']['embedHeightWidth'] as $breakpoint => $dimensions ) {
$css .= sprintf(
"\n\t@media (min-width: %spx) {\n\t\t.{$class_name} { min-height: %spx; }\n\t}\n",
$device_breakpoints[ $breakpoint ],
$dimensions['height'],
$dimensions['width']
);
}

The key reason here is that the embed may be rendered inside of a column which is narrower than the entire window, meaning that the media query won't produce the right result.

A feature query may also be utilized (e.g. @supports (contain: inline-size) { /*...*/ }) where relevant.

@westonruter
Copy link
Collaborator Author

cf. GoogleChromeLabs/layout-shift-terminator#8

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

1 participant