1

I'm trying to make a website which is similar to this https://www.netflix.com/in/title/80189221. I would like to know how to get the video in the middle of the page.
My code looks like this.

iframe {
    width:240px;
    height:160px;
    align: middle;
 }

I've also tried this:

iframe {
    width:240px;
    height:160px;
    margin-left: auto;
    margin-right: auto;
}

But nothing seems to be working.

Nithya Rajan
  • 4,722
  • 19
  • 30

2 Answers2

2

Add display:block; to the iframe

.ifrmae-holder {
    height: 100vh;
    position: relative;
}
iframe {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  -webkit-transform: translate(-50%,-50%);
  -moz-transform: translate(-50%,-50%);
}
<div class="ifrmae-holder">
<iframe width="560" height="315" src="https://www.youtube.com/embed/E4n7BQkOQ_s" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
Dharmesh Vekariya
  • 1,138
  • 2
  • 13
  • 31
Anuresh VP
  • 607
  • 6
  • 19
0

I think this is the easy way to center any content

js fiddle example here

.ifrmae-holder {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}
<div class="ifrmae-holder">
<iframe width="300" height="250" src="https://www.youtube.com/embed/E4n7BQkOQ_s" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
Razib Hossain
  • 708
  • 5
  • 13