Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make the Iframe responsive? #242

Closed
josuablejeru opened this issue Apr 30, 2020 · 8 comments
Closed

How to make the Iframe responsive? #242

josuablejeru opened this issue Apr 30, 2020 · 8 comments
Labels

Comments

@josuablejeru
Copy link

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!

@redshoga
Copy link

redshoga commented May 5, 2020

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"} />

@josuablejeru
Copy link
Author

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

@iiiok
Copy link

iiiok commented Jul 7, 2020

@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!

@ruisaraiva19 ruisaraiva19 pinned this issue Jan 24, 2021
@ruisaraiva19 ruisaraiva19 changed the title how to make the Iframe responsive How to make the Iframe responsive? Jan 24, 2021
@MichaelDimmitt
Copy link

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

@ruisaraiva19
Copy link
Collaborator

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

danfishgold added a commit to danfishgold/similarweb-playlist that referenced this issue Jul 9, 2021
@crysfel
Copy link

crysfel commented Dec 31, 2021

@redshoga your css solution works great, thanks!!

@juxuanu
Copy link

juxuanu commented Apr 3, 2023

containerClassName does not exist. What should be used?

@DjakaTechnology
Copy link

containerClassName does not exist. What should be used?

try className

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants