Embed
Embed copied to clipboard
Iframe code width and height
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 !
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.
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