Search code examples
htmlcsscss-positioncenter

How can we center an iframe inside an absolute positionned div


I tried to put the iframe tag inside an a tag and set its css to text-align:center, but it didn't work

Edit Sorry, I mislead I have an iframe

<div>
    <iframe type="text/html" width="640" height="360" src="https://www.youtube.com/..." frameborder="0" allowfullscreen=""></iframe>
    <button type="button">Ajouter la vidéo...</button>
</div>

the div is itself centered and has class

width: 500px;
position: absolute;
top: 35%;
left: 30%;
margin-left: -200px;
z-index: 3;

Solution

  • This code should solve your problem:

    img{
      display: block;
      margin: 0 auto;
    }