-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Add height:auto
to video
in Video block
#37052
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
Size Change: +21 B (0%) Total Size: 1.1 MB
ℹ️ View Unchanged
|
Perhaps we could do something similar to what we did in the twentytwentyone theme? |
But relying on a script to obtain the width/height on the frontend is not optimal for performance, right? That will result in layout shift when the script runs. I thought the point of browsers implementing a default The AMP plugin is obtaining the In any case, I'm seeing some strange browser behavior for |
I think we could combine the 2... A PHP implementation makes more sense than a JS one as it will be more performant and will avoid layout shifts like you said. |
My understanding is that only setting the |
The reason I'm a bit hesitant with using |
Hi, @westonruter Is this PR still relevant? |
@Mamaduka It's still relevant, yes, but in reality the issue is larger than this because the In the 4 years since I opened this PR (😊), I think the solution is to not only add // Set the width and height to reflect the captured intrinsic dimensions.
$processor->set_attribute( 'width', (string) $intrinsic_dimensions['width'] );
$processor->set_attribute( 'height', (string) $intrinsic_dimensions['height'] );
if ( 'VIDEO' === $processor->get_tag() ) {
// TODO: It's not clear why the aspect-ratio needs to be specified when the user agent style is already defining `aspect-ratio: auto $width / $height;`.
// TODO: Also, the Video block has styles the VIDEO with width:100% but it lacks height:auto. Why?
// TODO: Why does the Image block use width:content-fit?
$style = sprintf( 'height: auto; width: 100%%; aspect-ratio: %d / %d;', $intrinsic_dimensions['width'], $intrinsic_dimensions['height'] );
$old_style = $processor->get_attribute( 'style' );
if ( is_string( $old_style ) ) {
$style .= $old_style;
}
$processor->set_attribute( 'style', $style );
} As noted by the Before: intrinsic-dimensions-before.webmAfter: intrinsic-dimensions-after.webmSee also: |
Thanks for the update, @westonruter! It seems that we could start with #52185 and then move to other related PRs. |
Closing in favor of #70293 which includes the full fix. |
This amends #30092 which added
height:auto
to somevideo
elements but didn't include the video in the Video block.Description
In the AMP plugin we add
width
andheight
attributes to videos in order to prevent layout shifts, which are currently a reality with videos in the Video block since no dimensions are provided as they are forimg
elements:video-layout-shift.mov
However, at the moment adding the
width
andheight
is currently causing the video to be stretched. By addingheight:auto
, the stretching is eliminated.height:auto
height:auto
How has this been tested?
Screenshots
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).