Does anyone know how to do this? I had to use deprecated code to get it to center. I've tried div class center. But it's not working.
iframe {
display: block;
width: 800px;
height: 400px;
margin: 0 auto;
border: 0;
}
<iframe src="http://www.apple.com/"></iframe>
iframes display inline by default.
So if you are going with margin: auto; you will need to add display: block; as well.
Also for auto margins to work an explicit width must be set on the iframe.
This should work:
Code:iframe { display: block; width: 800px; height: 400px; margin: 0 auto; border: 0; }
Code:<iframe src="http://www.apple.com/"></iframe>
Many thanks, Elppa, for the great AND COMPLETE WITH COMPLETE CODE reply that worked, instead of posting the incomplete, condescending and arrogant reply immediately prior to yours.iframes display inline by default.
So if you are going with margin: auto; you will need to add display: block; as well.
Also for auto margins to work an explicit width must be set on the iframe.
This should work:
Code:iframe { display: block; width: 800px; height: 400px; margin: 0 auto; border: 0; }
Code:<iframe src="http://www.apple.com/"></iframe>
......instead of posting the incomplete, condescending and arrogant reply immediately prior to yours. When we ask for advice, it's not to be told by implication, "Hey, dummy.....
Many thanks, Elppa, for the great AND COMPLETE WITH COMPLETE CODE reply that worked, instead of posting the incomplete, condescending and arrogant reply immediately prior to yours.
When we ask for advice, it's not to be told by implication, "Hey, dummy, you should know enough that generally you do it the same as with other elements: margin: 0 auto."
If we KNEW that much, we wouldn't be here asking for decent, complete and applicable information. No one is asking for implied insults. In the future, angelwatt, save yourself the time and bandwidth by not posting such useless and pedantic crap, and take a lesson from Elppa about how an information forum is supposed to work in sharing USEFUL information instead of trying to impress others with your useless prowess.
We don't care what you know; on specific questions and trouble-shooting, we care about what you know which you are willing to share in detail as a colleague.
(EOM)
Hmm, I didn't think his post was arrogant. I sometimes don't post entire solutions on code forums just to have the OP get involved in the solution, and, let's face it, not everyone has time to solve someone else's problem in complete fashion, but provide a bump in the right direction.
Is there a way to implement these changes using inline CSS?
Example:
<span style="display: block; width: 800px; height: 400px; margin: 0 auto; border: 0;"><iframe src="http://mypage.com"></iframe></span>
OR something like...
<iframe src="http://mypage.com" height="400" width="800" display="block" frameborder="0" margin="0 auto" marginwidth="0" marginheight="0" scrolling="no"></iframe>
Thank you,
<iframe src="https://bing.com" scrolling="no"
style="display: block; width: 800px; height: 400px; margin: 0 auto; border: 0;">
</iframe>
Inline CSS isn't a great approach.