Tutorial: Making embedded YouTube videos responsive

Post a reply

Confirmation code
Enter the code exactly as it appears. All letters are case insensitive.
View more smilies
Smilies
:sn-1: :sn-2: :sn-3: :sn-4: :sn-5: :sn-6: :sn-7: :sn-8: :sn-9: :sn-10: :sn-11: :sn-12: :sn-13: :sn-14: :sn-15: :sn-16: :sn-17: :sn-18: :sn-19: :sn-20: :sn-21: :sn-22: :sn-23: :sn-24: :sn-25: :sn-26: :sn-27: :sn-28: :sn-29: :sn-30: :sn-31: :sn-32: :sn-33: :sn-34: :sn-35: :sn-36: :sn-37: :D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:
View more smilies

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review

I accept the Privacy policy.

   
  • Saved at

Expand view Topic review: Tutorial: Making embedded YouTube videos responsive

Tutorial: Making embedded YouTube videos responsive

by Selene310187 » Mon Feb 06, 2023 9:30 pm

The videos of the board are embedded via the custom YouTube BBCode of the Opt-In Cookie Manager extension for phpBB. If you are looking for a general solution, you find useful hints here.

Skip to the solution for the Opt-In Cookie Manager extension


This extension is great if you want to make the embedded YouTube videos of your phpBB board compliant with the GDPR (or similar regulations). But the videos that are embedded via the custom YouTube BBCode are not entirely responsive on mobile devices which means it's possible that things are cut off.

My previous workaround was using the CSS @media rule to set the width and height of the video for different screen resolutions. This mitigated most of the issue, however on some screens it could still happen. Today, I finally found a solution that works for all screen resolutions - the aspect-ratio property! I received the final hint from this site.



All I needed to do, was modifying the youtube_bbcode_switch_on.css which you can find under ext\chris1278\cookie\styles\all\theme.

Open the file, delete the entire code and replace it with my modified version:

Code: Select all

/* These CSS settings are used for the info box that is displayed when the Youtube switch is set to false but a video is embedded in the post with the BBcode. */
.yt_video_switch_false {
	display: none
}

/* These CSS settings are used to format the video that is displayed. */
.yt_video_layer {
	max-width: 600px;
	max-height: 345px;
	padding-bottom: 40px;
}

.yt_video_layer iframe, .yt_video_layer object, .yt_ideo_layer embed {
	position: relative;
	width: 100%;
	height: unset;
	aspect-ratio: 16/9;
}
Save the file and purge the cache of your board (otherwise the changes won't take effect).


Here's an embedded video for testing:
A video from YouTube usually appears here. Please contact an administrator.
A video from YouTube usually appears here. Please contact an administrator.
If you don't have a mobile device at hand, open up the Developer Tools of your browser and play around with different screen resolutions:
Chrome/Opera
Firefox

Top