-1

I am new to HTML and CSS coding and I got a challenge right now. I am currently looking for the solution on how I can center my iFrame video in the center of the page.

HTML

<section id="video">
  <div class="row">
    <div class="video-container">
      <iframe width="853" height="480" src="https://www.youtube.com/embed/rXuWb0RXfEI" frameborder="0" allowfullscreen></iframe>
    </div>
  </div>
</section>

CSS:

.video-container {
   position:relative;
   padding-bottom:56.25%;
   padding-top:30px;
   margin-top: 100px;
   height:0;
   overflow:hidden;
}

.video-container iframe,
.video-container object,
.video-container embed {
     position: absolute;
     width:80%;
     height:80%;
}

.row {
     text-align: center;
}

I hope someone can help me with this issue...

Cindy
  • 140
  • 9
Tim B.
  • 5
  • 2
  • 1
    Possible duplicate of [Best way to center a
    on a page vertically and horizontally?](https://stackoverflow.com/questions/356809/best-way-to-center-a-div-on-a-page-vertically-and-horizontally)
    – Temani Afif Dec 21 '17 at 11:03
  • this may help; https://stackoverflow.com/questions/8366957/how-to-center-an-iframe-horizontally – Dr Upvote Dec 21 '17 at 11:04
  • Possible duplicate of [Vertically center responsive iframe](https://stackoverflow.com/questions/21645291/vertically-center-responsive-iframe) – Rob Dec 21 '17 at 11:22

3 Answers3

1

Just try to change this :

.video-container iframe,
.video-container object,
.video-container embed {
    position: absolute;
    top: 10%;
    left: 30%;
}
3rdthemagical
  • 5,271
  • 18
  • 36
Cindy
  • 140
  • 9
0

you can actually just leave out the lower part of your css and just use the following:

.video-container {
  position: relative;
  padding-bottom: 56.25%;
  padding-top: 30px;
  margin-top: 100px;
  height: 0;
  overflow: hidden;
  width: 80%;
  height: 80%;
  margin: 0 auto;
}
Tobias Grunwald
  • 161
  • 1
  • 3
  • 14
0
.videoWrapper {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    padding-top: 25px;
    height: 0;
}
.videoWrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;

<div class="videoWrapper">
    <!-- Copy & Pasted from YouTube -->
    <iframe width="560" height="315" src="https://www.youtube.com/embed/wmgWITMWcmE?rel=0&amp;controls=0&amp;showinfo=0" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen></iframe>
</div>
  • We're almost there... I want this not 100% width, but 80%. If I use 80%, the video will end up on the left side of the page instead of in the center. – Tim B. Dec 22 '17 at 14:47