oscarotero / Embed

Get info from any web service or page
MIT License
2.08k stars 312 forks source link

Iframe code width and height #479

Open wyllyjon opened 2 years ago

wyllyjon commented 2 years ago

Hello,

I allow users to import some videos in their profile, and it can be done from various sources (Vimeo, dailymotion, Youtube, etc.) But the sizes of the iframe got from $info->code->html are not the same acording to the source.

Is there a way (except javascript) to set the width and height in the code with your library ?

Thanks for the help !

oscarotero commented 2 years ago

The best way to set a width & height to iframes is with CSS. Websites don't always return width and height values or they don't match with the values in the html code. Sometimes is more useful the aspect-ratio value, because it allows to set any size to the iframe keeping the same proportions.

oscarotero commented 2 years ago

You can use the aspect-ratio css property for that https://developer.mozilla.org/en-US/docs/Web/CSS/aspect-ratio Or if you need compatibility with old browsers the padding trick: https://nikitahl.com/css-aspect-ratio