INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

anyone know how to center an image in an iframe?

anyone know how to center an image in an iframe?

(OP)
this dose not work

CODE

<iframe  valign="center" src="images/woodscrew.jpg" name="content2"  backcolor height="140" width="140"></iframe> 

RE: anyone know how to center an image in an iframe?

Images are inline elements so just apply

CODE --> CSS

text-align: center; 
to the element.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: anyone know how to center an image in an iframe?

Hi

Quote (Chris)

Images are inline elements
Correct. But inline elements exist only in HTML documents. However, there is no HTML document inside the OP's iframe, only the bare image. Are you sure you can apply CSS to it ?

Feherke.
feherke.github.io

RE: anyone know how to center an image in an iframe?

No idea, not something I've tested and the TS is going to learn more by trying it rather than having a ready made solution "spoonfed" to them.

But an <iframe> without a URL value for the src attribute is just a block level container.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: anyone know how to center an image in an iframe?

Hi

Quote (Chris)

No idea, not something I've tested and the TS is going to learn more by trying it rather than having a ready made solution "spoonfed" to them.
I tried it out. Although I was sure will not work. Actually, I am sure there is no way to solve this with HTML and/or CSS.

leo57, I see absolutely no reason to load an image in an iframe. I suggest to not do it. But if you really have to, you may try something like this :

CODE --> JavaScript

document.querySelector('iframe[name="content2"]').contentWindow.addEventListener('load',function(e){e.target.body.style.textAlign='center'},false) 
Works in Gecko and newer Trident. Should work in WebKit too, but I was unable to test it. In Presto there is no need to do anything as the image inside the iframe appears centered by default.

Feherke.
feherke.github.io

RE: anyone know how to center an image in an iframe?

I agree with feherke, there's no real reason to load a single image in an iframe. If you load an html page that shows the image that may be one way to get it to center, bur really why are you loading an image in an iframe? Why not simply use a img tag in a div?

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close