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>
I think if you add margin: auto; to the div below it should work.
center iframe
one solution is:
css:
fiddle: http://jsfiddle.net/h9gTm/
edit: vertical align added
css:
fiddle: http://jsfiddle.net/h9gTm/1/
Edit: FLEX solution
using
display: flex
on the<div>
fiddle: http://jsfiddle.net/h9gTm/867/
You could easily use display:table to vertical-align content and text-align:center to horizontal align your iframe. http://jsfiddle.net/EnmD6/7/
version with table-row http://jsfiddle.net/EnmD6/9/
First remove
position:absolute
ofdiv#iframe-wrapper iframe
, Removeposition:fixed
and all other css fromdiv#iframe-wrapper
Then apply this css,
FIDDLE DEMO
Try this:
If all you want to do is display an iframe on a page, the simplest solution I was able to come up with doesn't require divs or flex stuff is:
And then the HTML is just:
If this is all you need you don't need wrapper divs to do it. This works for text content and stuff, too.
Fiddle.
Also this looks even simpler.