How to align iframe always in the center

alignment, css, html, iframe

Solution

Center iframe

Edit: FLEX solution

Using `display: flex` on the `<div>`

div {
    display: flex;
    align-items: center;
    justify-content: center;
}

JSFiddle: https://jsfiddle.net/h9gTm/867/

One solution is:

div {
  text-align:center;
  width:100%;
}
div > iframe{
  width: 200px;
}
<div>
  <iframe></iframe>
</div>

JSFiddle: https://jsfiddle.net/h9gTm/

edit: vertical align added

css:

div {
    text-align: center;
    width: 100%;
    vertical-align: middle;
    height: 100%;
    display: table-cell;
}
div > iframe{
  width: 200px;
}
div,
body,
html {
    height: 100%;
    width: 100%;
}
body{
    display: table;
}

JSFiddle: https://jsfiddle.net/h9gTm/1/

Problem

I have an iframe surrounded by div element and I am simply trying to position it always in the center. here is my jsfiddle effort : jsfiddle and trully believe that someone could help because I am sure that it is something really simple but I just can not see it. Here is the HTML itself: ``` <div id="top-element">Some div that has greater width than the inner div</div> <div id="iframe-wrapper"> <iframe src="http://www.apple.com/" scrolling="auto"></iframe> </div> ```

Original source

Related problems