react-youtube icon indicating copy to clipboard operation
react-youtube copied to clipboard

How to make the Iframe responsive?

Open josuablejeru opened this issue 4 years ago • 6 comments

Responsive Iframe

Hi first I want to thank you for your work, it has really an easy api to work with!

Here my question: I had a really hard time try to make the iframe responsive on mobile and desktop. Did anyone have an Idea how we could implement a autoresize feature to this Component so you can make it responsive by a prop?

(If it is not possible... can anyone give me a hint how to make my iframe responsive in a material-ui card?)

Thanks for your time!

josuablejeru avatar Apr 30 '20 19:04 josuablejeru

It could be implemented by using containerClassName props.

.youtubeContainer {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 56.25%;
  overflow: hidden;
  margin-bottom: 50px;
}

.youtubeContainer iframe {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}
<YouTube videoId="2g811Eo7K8U" containerClassName={"youtubeContainer"} />

redshoga avatar May 05 '20 06:05 redshoga

@redshoga Thank you for taking the time to answer my question!

josuablejeru avatar May 06 '20 18:05 josuablejeru

@redshoga got a real good solution for this component. I tried useFre, ReactDOM.findDOMNode, node.getBoundingClientRect().width. Node of them works for me.

CSS solution rocks!

iiiok avatar Jul 07 '20 07:07 iiiok

@josuablejeru , is this issue ready to be closed? Or is there something still pending?

MichaelDimmitt avatar Jan 24 '21 18:01 MichaelDimmitt

@MichaelDimmitt the comment above from @redshoga works as expected. This issue is style related and doesn't concern YouTube Player API.

ruisaraiva19 avatar Jan 24 '21 19:01 ruisaraiva19

@redshoga your css solution works great, thanks!!

crysfel avatar Dec 31 '21 17:12 crysfel

containerClassName does not exist. What should be used?

juxuanu avatar Apr 03 '23 20:04 juxuanu

containerClassName does not exist. What should be used?

try className

DjakaTechnology avatar Apr 16 '23 13:04 DjakaTechnology