0

How do I set an iframe view point to auto adjust for mobile devices at 100% but not to be bigger than width="600" height="400" when viewing on a laptop or computer monitor and to center it?

Example of Html/CSS I am using but is adjust to 100% of all screens:

.iframe-container{
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; 
  height: 0;
}
.iframe-container iframe{
  position: absolute;
  top:0;
  left: 0;
  width: 100%;
  height: 100%;
} 
<div class="iframe-container">
    <iframe src="https://www.youtube.com/embed/tgbNymZ7vqY" width="600" height="400"></iframe>
</div> 
Joundill
  • 6,828
  • 12
  • 36
  • 50
Someone
  • 1
  • 1

2 Answers2

0

You need to add media query for this.

/* Desktop */
.iframe-container iframe {
  width: 600px;
  height: 400px;
}

/* Mobile */
@media screen and (max-width: 768px) {
  .iframe-container iframe {
    width: 100%;
    height: auto;
  }
}
shutupchigo
  • 703
  • 1
  • 7
  • 19
0

Adding on to the previous answer, to align it in the middle:

.iframe-container {
    width:100%;
    text-align:center;
}
Jennift
  • 667
  • 1
  • 6
  • 13