Great job with the responsive youtube embed hack, here is the updated solution on codesandbox - https://codesandbox.io/s/admiring-parm-mmj5xw?file=/components/VideoSection/index.js:1114-1251
You can view the final result here -
<div
class="grid gap-0 grid-cols-1
grid-rows-1 place-items-center
content-center pl-5 pr-5" // <<< This part is unnecessary.
className={css.videoResponsive}
The issue where className={css.videoResponsive}
wasn't being applied has been resolved by removing the unnecessary tailwind classes like class=grid gap-0
, as the YouTube video responsiveness code now handles page alignment.
In React 16, using class
is functional but triggers a warning that can be viewed in your console. It's recommended to stick to consistently using className
when writing JSX.
I have also eliminated the width/height specifications from the iframe element.
Update
A new requirement has come up for Desktop to be centered and 50%, while mobile remains full width.
The following serves as guidance rather than a permanent fix:
@media screen and (min-width: 769px) {
.videoResponsive {
overflow: hidden;
position: relative;
width: 100%;
}
.videoResponsive::after {
padding-top: 56.25%;
display: block;
content: "";
border: 1px solid red;
}
.videoResponsive iframe,
.videoResponsive object,
.videoResponsive embed {
border: 0;
position: absolute;
width: 50%;
height: 915px;
left: 0;
right: 0;
margin: 0 auto;
}
}
@media screen and (max-width: 768px) {
.videoResponsive {
overflow: hidden;
position: relative;
width: 100%;
}
.videoResponsive::after {
padding-top: 56.25%;
display: block;
content: "";
}
.videoResponsive iframe,
.videoResponsive object,
.videoResponsive embed {
border: 1px solid red;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}
You can utilize media queries to adjust behavior, but be aware that the padding-top
adds extra space which may require tweaking.
The codesandbox link above showcases the updated outcome https://codesandbox.io/s/admiring-parm-mmj5xw?file=/components/VideoSection/VideoSection.module.css:680-1556