-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Can't style embedded videos properly due to inline width & height #8383
Comments
This is an interesting one. In the editor we try to detect iframed content with a fixed width and height, and make it responsive while preserving the aspect ratio. On the front end though, the HTML put into the page is whatever oEmbed gives us, and so it'll have the fixed width and height. So that width and height is coming from YouTube or Vimeo's oEmbed API, not from Gutenberg. How did we solve this in the classic editor? Was there javascript or different styles on the front end? Or did we strip out height and width? |
@notnownikki Using the Classic Editor, Video Embeds still specify the width & height for the iframe. This is controlled by It works in the Classic Editor because it's only dealing with one width, which is basically the same width that Gutenberg uses when you haven't selected the Wide or Full buttons. Since Gutenberg is now allowing extra widths (i.e. the wide and full widths), it either (A) needs to let us supply those widths in the same way that we can specify Basically, Gutenberg has introduced this issue by introducing the Wide and Full widths, so likewise, it also needs to provide a solution for it as well. |
Thanks, that's filling in bits of the puzzle for me!
I need to look more into the internals of how this works, but I'm pretty sure this is the way we need to go with things, because...
... all the editor does when it saves an embed block is to put the URL on its own line, and oEmbed does the rest when the post is rendered, so by that point, Gutenberg isn't involved. The bit about (A) that seems trickiest to me at the moment is that we wouldn't have a single content width for the post, so the problem becomes how we let oEmbed know that one bit of embedded content is @karmatosed, @jasmussen might have some input here? |
Would it be a solution to provide two configurations for embedded video, perhaps as advanced settings in the sidebar?
Edit: Gutenberg might not have a |
This would get 100% of my vote! However my CSS-fu hasn't been able to come up with anything that makes the embed 100% width and keeps the aspect ratio. It's not as simple as setting the iframe width to |
I could swear we had this working at one time, with CSS in place for it. Perhaps this regressed a bit? I can take a look next week. The basic idea is that the video is 100% full wide. We then decide an assume an aspect ratio for the video, 16:9, and use that knowledge to use paddings to define the aspect ratio. It's all in this pamphlet: http://www.mademyday.de/css-height-equals-width-with-pure-css.html Sidenote, it would be nice to expand this further so the user can choose the aspect ratio from a sidebar dropdown, like 1:1 (square) 4:3, etc. I can take a look at this next week if it regressed. |
Ah. We can't assume an aspect ratio of 16:9 for video any more, because YouTube have started putting 4:3 videos in 4:3 aspect ratio. That's why the code in the embed block (which I think has regressed due to some style changes, but fundamentally works) gets the initial height and width and calculates an aspect ratio so that the iframe can resize correctly. |
Oh that's interesting. I'll take a look next week and see how we can handle that. |
Perhaps the embed block can get the aspect ratio (should be able to access to that information when it renders the preview) and set styles on the block so that the CSS can be told about the aspect ratio? |
That would be sort of amazing. We'd have to work out the math to figure out the percentage, though, but that should be simple enough:
|
Yep, the HTML that would be embedded in the front end is available to the editor, so if we get the |
I've just been playing around with some styles, using the browser dev tools, based on that 'mademyday' link and your solution might actually work. I altered Because all my content is inside a containing div to give it a boxed layout, I have to use negative margins for the You also have to specifically set In then end, this is what I was able to display, which was the original goal. |
That's great! I think that having the block apply the correct class for the content's aspect ratio will work nicely then, and we should be able to apply it to any embed that comes in an iframe with fixed height and width. I'll update here when there's a PR up 😄 |
In progress PR at #9500 That will apply the correct class names, we need to get the CSS written that applies the correct padding etc. |
#9500 has been merged, and on embeds that have a fixed size iframe, it sets CSS classes that allow it to resize and keep the correct aspect ratio. You'll see a new wrapper div with classes that look like |
Hi there. I'm working on a custom Wordpress theme and trying to use Gutenberg. The responsive video thing is one of the last things I'm running into. In my googling I found this thread :) Do you know when this will be released? (I just updated to 3.8.0 today and don't see it) (I like the way y'all are thinking about it, btw) |
Hi @shaunrfox, the pull request for this feature was merged for the 3.9 milestone. We hope to release 3.9 release candidate today (which you can manually install, follow https://make.wordpress.org/test/ for details), and push 3.9 out hopefully next week. |
Ok, awesome! Thanks for the reply @jasmussen |
@maddisondesigns that's strange, we use a Vimeo video on the demo page and it gets the classes applied... Could you try embedding https://vimeo.com/22439234 and see what happens? Also, what's the address of the video you're embedding there? I'll see if there's anything unexpected in the embed response that stops us calculating the correct styles. |
@notnownikki I tried adding your Vimeo vid and it added the aspect ratio classes ok. I also tried adding in the same video in my screenshot above (https://vimeo.com/139290912), again, but it still didn't added the aspect ratio classes. While your video did get the classes on the front-end, it also caused a number of issues in the editor though. First up, I embedded the video twice, I wanted to see if it displayed properly in wide/full widths. The second one that I embedded though, displayed at a completely different width than the first embed. In the following pic, neither of those embeds have the wide/full buttons selected. They should appear identical, but they don't. Here's a better look at the second embed that I added. You can see a heap of empty space in the embed container. After embedding multiple vids, the whole editor goes completely weird. When you try to scroll down the page, it jumps back up again. If you do manange to scroll down, and then try to scroll up, you get huge gaps of white space between the blocks. Here's a vid... This last issue I've raised before but it was marked as low priority, which it obviously shouldn't be because it's still happening - #8603 |
@maddisondesigns thanks. I'm looking at this now. The video you're using isn't getting the aspect ratio recognised, so that's why it's not getting responsive classes applied to it, so I'll see what's happening there. Embedding the same video twice and the second time it doesn't get the classes applied at all - not sure why that's happening, but I'm on it. |
@maddisondesigns the scroll problem seems to be related to drag-n-drop and toolbars, I've pinged @nosolosw who knows more about that. I'm on the way to a fix for the other issues. |
Hi - regarding the scroll. Is #8603 that we're talking about, right? That has nothing to do with drag-n-drop. As @maddisondesigns suggested, the problem is reproducible when the embed is selected. My guess would that the code that makes the toolbar pinnable is somewhat related to that? |
Yes, #8603. Sorry, I misunderstood, not dnd. |
I may have fixed the scrolling issue in #8603 (comment). |
Can you help me getting this work on the front-end? In the backend everything works for me and also in the front end the embeds are getting their respective classes attached like:
But where can I get the responsive styling of these classes from in my frontend? |
If I understand properly, the reason it doesn't work in the front-end is because of themes that have not yet adapted. The theme needs to opt into Gutenberg styles, and when they do, it will work correctly on the front-end. |
Here's basic front-end css:
You are welcome. |
Thank you so much for posting the CSS - fixed my issue marvelously!! |
This was definitely my solution, thank you very much boss! |
Hey, I've just started using Gutenberg so I'm not sure if the code has changed. But when I was putting in @jasomdotnet code it showing up blank. But this works for me! figure.wp-block-embed.is-type-video, .wp-block-embed__wrapper { Thanks for this! |
@Mishkamshka thank you so much... this saved me my afernoon! |
Describe the bug
There's numerous issues open that discuss the inability to style various blocks so I'm not going to repeat all that again here. The only thing I will say is that we need the ability to specify the content width, and Wide width, at the very minimum.
When you insert a YouTube or Vimeo embed Block, it adds inline width and height to the iframe:
This causes the content to end up looking something like this (when you have Wide and Full videos):
Whilst its possible to override the width settings by doing something like
.wp-block-embed.is-type-video iframe {width: 100%;}
, this just makes it look even worse as we can't control the height and the vid just ends up looking squished.There needs to be a better way to style these video embeds on the front-end.
To Reproduce
Steps to reproduce the behavior:
Desktop (please complete the following information):
Some related issues:
#5650
#6131
The text was updated successfully, but these errors were encountered: