How can I make an image appear in the centre of the page?

A

Ant

Hi,

I'm trying to make the image appear in the centre of the page no matter what
the resolution is.

I had the idea of creating a 1*1 table whose dimensions were the size of the
viewable browser area and then centering the image in that but I'm running
into some problems.

Then I had the idea of setting the IMG hspace and vspace attributes but then
I realised that they would need ot be dynamically calculated.

So am I missing an obvious method?

If so then please enlighten me!

Cheers
 
D

Des

if this is in a table try this

<table cellpadding="0" cellspacing="0" width="900" align="center">

this will keep things centeral

Desmond.
 
T

Toby Inkster

Ant said:
I'm trying to make the image appear in the centre of the page no matter
what the resolution is.

The best reliable way is to put it as a background image:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<title>some title</title>
<style type="text/css">
body
{
background-image: url("foo.jpeg");
background-repeat: no-repeat;
background-position: center center;
}
div
{
position: relative;
width: 20em;
left: -99em;
}
</style>
<div>alt text</div>
 
B

Barbara de Zoete

[placing it as a background image]

Will be a problem for printing though.

What will be? What are you referring to? Where is the quote from the post you
reply to? Who wrote it?

--
,-- --<--@ -- PretLetters: 'woest wyf', met vele interesses: ----------.
| weblog | http://home.wanadoo.nl/b.de.zoete/_private/weblog.html |
| webontwerp | http://home.wanadoo.nl/b.de.zoete/html/webontwerp.html |
|zweefvliegen | http://home.wanadoo.nl/b.de.zoete/html/vliegen.html |
`-------------------------------------------------- --<--@ ------------'
 
A

Ant

Thanks everyone for the replies!

I should have mentioned that I would like the image to act as the entrance
to a site - so you click on the picture and get taken to the main page - so
I don't think the background method will work for this - my bad, should have
said.
 
J

Jedi Fans

Ant said:
Thanks everyone for the replies!

I should have mentioned that I would like the image to act as the entrance
to a site - so you click on the picture and get taken to the main page - so
I don't think the background method will work for this - my bad, should have
said.
css:
img.central{position:absolute;width:WIDTHOFIMAGEpx;height:HEIGHTOFIMAGEpx;left:50%;top:50%;margin-top:-HALFOFIMAGEHEIGHTpx;margin-left:-HALFOFIMAGEWIDTHpx;}

html:
<img src="enter.png" class="central" alt="Enter the website" />
 
A

Ant

wow! thanks!!

that did the job perfectly

Jedi Fans said:
css:
img.central{position:absolute;width:WIDTHOFIMAGEpx;height:HEIGHTOFIMAGEpx;left:50%;top:50%;margin-top:-HALFOFIMAGEHEIGHTpx;margin-left:-HALFOFIMAGEWIDTHpx;}

html:
<img src="enter.png" class="central" alt="Enter the website" />

--
Hope This Helped and MTFBWY...
Kieren aka JediFans - <URL:http://jedifans.com/>
The Force Is With Me, SuSE Linux Professional 9.3, Mozilla Firefox 1.0.6,
Mozilla Thunderbird 1.5 Alpha 2 and Revenge Of The Sith!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top