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>
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
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/
I think if you add margin: auto; to the div below it should work.
div#iframe-wrapper iframe {
position: absolute;
top: 0;
bottom: 0;
left: 0;
margin: auto;
right: 100px;
height: 100%;
width: 100%;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With