/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Hello, Question about centering an image

Hello everyone, this might be a simple thing to do for msot of you, but for a newbie like my self its a brain twister.

Page im trying to center image on: [url]www.primal-instinct.org[/url]

I have been trying to get this image to center for everyone, and since everyone has different resolutions, it always looks different for everyone. My question is, is it possible to have it center for everyone ? I think I have seen this on other peoples enter screens, but im not sure what they did, and couldnt find any pages to try and look at the source… if someone could help me with this issue I would greatly appreciate it.

Thanks ahead of time,

-shahiz.

to post a comment
HTML

20 Comments(s)

Copy linkTweet thisAlerts:
@substanceJan 16.2007 — If you use the <center> tags it should "center" cross-browser i.e.

<center>

<IMG SRC="http://geo.yahoo.com/serv?s=76001405&t=1168949316&f=p10w10" ALT=1 WIDTH=1 HEIGHT=1>

</center>
Copy linkTweet thisAlerts:
@shahizauthorJan 16.2007 — im at work, so I cant really do it atm, but will this also center it from top to bottom?

thanks alot, much appreciated.

-shahiz
Copy linkTweet thisAlerts:
@substanceJan 16.2007 — No that HTML tag will not vertically center the image, just horizontally.

It appears to be vertically centered (by accident obviously), you can do that by putting it in a table. However I never use tables, it can be done with CSS aswell.

I have noticed that your Source code is not good. It is broken at the end.

Did you code that page?
Copy linkTweet thisAlerts:
@shahizauthorJan 16.2007 — No that HTML tag will not vertically center the image, just horizontally.

It appears to be vertically centered (by accident obviously), you can do that by putting it in a table. However I never use tables, it can be done with CSS aswell.

I have noticed that your Source code is not good. It is broken at the end.

Did you code that page?[/QUOTE]


well, i just used macromedia dreamweaver, im not exactly good at coding or anything that has to do with html really, i stopped messing around with it ages ago. Whats messed up about it? I cant really tell the diff but just to know ;p

thanks,

-shahiz.
Copy linkTweet thisAlerts:
@CharlesJan 16.2007 — well, i just used macromedia dreamweaver[/QUOTE]That would explain it then. Dreamweaver, like all WYSIWYGs, doesn't use HTML or XHTML. It uses what we call "tag soup".

Your best bet is to go back and learn HTML and re-do the site from the start. But until then you'll want to go back to using Dreamweaver.
Copy linkTweet thisAlerts:
@substanceJan 16.2007 — I have just tried to validate your page as XHTML Transitional.

It Failed with 25 errors.

Can I ask why you chose XHTML? The errors that appear show that you do not have an understanding of XHTML. You need to go back and Learn a bit of HTML and XHTML.

[B]Here are some of the most obvious mistakes:[/B]

You have code outside the </HTML> (html end tag).

You have in-line styles on the html page; use a seperate style sheet for this.

[B]XHTML mistakes:[/B]

no "alt" specified in the IMG tag

Always use Lower-case tags

I can take a look at the code and re-write it for you if you want?
Copy linkTweet thisAlerts:
@WebJoelJan 16.2007 — Don't use "<center>", -that is a deprecated tag ("old", out-of-favor, etc.).

To 'center' an image, you state it's width, and give it a "margin:auto;", like this:

<img src="newsplash.png" [B]width="1022"[/B] height="162" vspace="260" border="0" usemap="#Map" [B]style="margin:auto;" [/B]/>

This will 'auto-adjust' the free-space to the left & right of the image based upon the stated width ("1022"), and the visitor's viewscreen...

And to really do the image justice, -let's css the whole thing to:

<img src="newsplash.png" usemap="#Map" [B]style="width:1022px; height:162px; border:0; margin:260px auto;" [/B]/>

This says exactly the same thing, and will validate, and it more 'browser-friendly' than what you are currently using. ?

Note that with [I]style=""[/I], you state the pixel values with "px", but that "0" ("zero") can be just "0" and doesn't have to be "0px". Zero is zero, whether it's pixels (px), points (pt), centimeters (cm), inches (in), em-space (em) ex-space (ex), etc.
Copy linkTweet thisAlerts:
@shahizauthorJan 16.2007 — I have just tried to validate your page as XHTML Transitional.

It Failed with 25 errors.

Can I ask why you chose XHTML? The errors that appear show that you do not have an understanding of XHTML. You need to go back and Learn a bit of HTML and XHTML.

[B]Here are some of the most obvious mistakes:[/B]

You have code outside the </HTML> (html end tag).

You have in-line styles on the html page; use a seperate style sheet for this.

[B]XHTML mistakes:[/B]

no "alt" specified in the IMG tag

Always use Lower-case tags

I can take a look at the code and re-write it for you if you want?[/QUOTE]


Yeah, I am going to re-read the whole html goodies page. And get back into it now that I have more time. Before I was more into gaming and that took up about 90% of my time after work. Now I spend most of my time reading. (tho im still a gamer at heart)

Anyways yes, If you can do that for me I would greatly appreciate that as well. Thank you all so much for the extremely fast replies.

And webjoel, thanks alot im going to try that as well when I get home.

-shahiz.
Copy linkTweet thisAlerts:
@CharlesJan 16.2007 — Yeah, I am going to re-read the whole html goodies page. [/QUOTE]No, for the Love of God, or the W3C, don't do that! It's full of errors and omissions. It's the worst thing that I've seen on the web. If you must use a tutorial seek out the W3Schools. It's still full of errors but it's not so bad.

For the only real thing, and there is no substitute, read, mark, learn and inwardly digest http://www.w3.org/TR/html401/ .
Copy linkTweet thisAlerts:
@substanceJan 16.2007 — Here is the code I have done for you, it now validates as XHTML. I have created a CSS style sheet for all the formatting (background colour etc.) to get you started. Try not to use in-line styles.

Any problems just ask.

[upl-file uuid=5ec4dbe9-d930-4c7f-a4bd-15d8875aeedc size=1kB]instructions.txt[/upl-file]
Copy linkTweet thisAlerts:
@shahizauthorJan 16.2007 — Thank you Substance, I will check it out when I get home from work. I cant even download a txt file here without one of the techies coming down to lecture me, so ill have to wait. ?
Copy linkTweet thisAlerts:
@CentauriJan 17.2007 — Here is the code I have done for you, it now validates as XHTML. I have created a CSS style sheet for all the formatting (background colour etc.) to get you started. Try not to use in-line styles.[/QUOTE]

Wha...? First you chastise shahiz for using XHTML transitional and inline styles, then you go ahead and use it in your "code", which is full of deprecated inline style tags...... The page STILL does not validate anyway, because if you had looked closely you would have noticed the part throwing most of the errors is generated by the op's host.

And you still didn't address the issue of the vertical centering....
Copy linkTweet thisAlerts:
@shahizauthorJan 17.2007 — Well, either way I appreciate any answers I got, im not sure whats wrong with any of the code stuff hehe, im just happy that I got linked to a site to start learning from, and that people tried to help me. ?

So there is a way to center it verticaly Centauri?

Thanks again for reading ?
Copy linkTweet thisAlerts:
@substanceJan 17.2007 — Wha...? First you chastise shahiz for using XHTML transitional and inline styles, then you go ahead and use it in your "code", which is full of deprecated inline style tags...... The page STILL does not validate anyway, because if you had looked closely you would have noticed the part throwing most of the errors is generated by the op's host.

And you still didn't address the issue of the vertical centering....[/QUOTE]


I was just trying to give shahiz a heads-up. I don't have time do all of their work, I am a busy person.

I took the time to give shahiz a head start into using XHTML and CSS, its now up to shahiz to continue with that.

If you had looked closely my XHTML [U]does[/U] validate thankyou, it's up to shahiz to change the host.

Centauri, with all of your free time used up [U]nit-picking[/U], you must have forgotten what this forum is for. How about you put this free time to good use by addressing the vertical centering issue..........
Copy linkTweet thisAlerts:
@CentauriJan 17.2007 — :o ?

In the interest of utilising this forum to promote the sharing of ideas, observations, and knowlege for everyone's benefit :rolleyes: lets have a look at the page in question.

The first problem is that, due to the use only of an image and an image map, there is no semantic information on this page of benefit to screen readers, search engines etc. One should consider content first, then presentation. To get some content on this page, we can use header tags to describe the page - in this case h1 tags to name the guild, h2 tags to describe the guild, and h3 tags to show this is an entry screen. The links can be a simple unordered list. As all this pertains to each other, grouping everything within a div is logical (and neccessary for presentation later).

This then gives the following html: [CODE]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Primal Instinct [3.14] Age Of Conan Guild</title>
<link rel="stylesheet" type="text/css" href="core.css">
</head>

<body>
<div id="entry">
<h1>Primal Instinct</h1>
<h2>Age of Conan Guild</h2>
<h3>Enter</h3>
<ul>
<li><a href="http://www.primal-instinct.org/main.html" title="Enter the Main site">Site</a></li>
<li><a href="http://www.primal-instinct.org/phpBB2" title="Go to the Forums">Forum</a></li>
</ul>
</div>
</body>
</html>[/CODE]


Note the use of html 4.01 strict doctype - the best choice for new pages where special benefits of xhtml are not needed. With the extra code the host of this site adds to the bottom of the file, this page will also not validate (it won't with any doctype), however, as in substance's example, the entered code is valid. If the above page is viewed without any styling, then it DOES make sense.

Note that, besides the containing div, no consideration has been given to any visual presentation. The styling css follows in next post.
Copy linkTweet thisAlerts:
@CentauriJan 17.2007 — With the graphic used, there is no requirement for the h1, h2, and h3 elements to be visible on the page, so we can reduce the text height to 1px, indent them off the page, and float them for good measure so they don't take any height.

The containing div can vertically center everything by assigning a height equal to the graphic, absolutely positioning it 50% from the top, then pulling it back up half the height of the graphic using a negative top margin.

The ul can display the graphic in its background - the ul is given a width and height equal to the graphic, and the auto left and right margins center things horizontally.

The links text does not need to be visible, the links just needing to emulate the image map. This is done by setting the a tags to display as a block 100px wide and 30px high, with the text indented way off to the left. These are transparent due to no background.

The li tags can then be floated left so that the link blocks are positioned beside each other, and then given the appropriate margins and padding to position them over the "site" and "forum" text on the background graphic.

The core.css file (keeping substance's file name) would then look like [CODE]* {
border: 0;
margin: 0;
padding: 0;
}
body {
background-color: #000000;
color: #FFFFFF;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
#entry {
position: absolute;
height: 162px;
top: 50%;
width: 100%;
margin-top: -81px;
}
#entry h1, #entry h2, #entry h3 {
font-size: 1px;
text-indent: -1000px;
float: left;
}
#entry ul {
display: block;
list-style: none;
height: 162px;
width: 1022px;
background-image: url(newsplash.png);
margin: 0 auto;
}
#entry li {
float: left;
display: inline;
margin-top: 126px;
margin-left: 45px;
margin-right: -35px;
padding-left: 10px;
}
#entry a {
display: block;
width: 100px;
height: 30px;
text-indent: -1000px;
}
[/CODE]


Note the first declaration zeros any browser default element margins, paddings, and borders and gives a level playing field to start. The body tag styling sets background and foreground (text) colours and base text type and size.

And there it is - semantically useful and centred.

Cheers

Graeme
Copy linkTweet thisAlerts:
@substanceJan 17.2007 — Centauri,

Fantastic explaination, I think shahiz should be good to go now ?.

You are a Gentleman and Scholar.
Copy linkTweet thisAlerts:
@shahizauthorJan 17.2007 — Centauri,

Fantastic explaination, I think shahiz should be good to go now ?.

You are a Gentleman and Scholar.[/QUOTE]


Indeed.

I am once again at work.

I took all of the advice on this thread and started reading the w3c tutorials, and most of it is pretty common sense so far, but ill go thru it to learn how to do the things correctly.

Also I would like to thank all of you again for the fast responses and help you have given me the last 2 days. (especially centauri and substance)

-shahiz.
Copy linkTweet thisAlerts:
@WebJoelJan 19.2007 — (post was answered) dble post:okay to remove this one
Copy linkTweet thisAlerts:
@WebJoelJan 19.2007 — -joining the thread a little late,....free time to good use by addressing the vertical centering issue....[/QUOTE] but you can center an image horizontally AND vertically on a page, if you know the dimensions of the image. If the image is, say, 500px wide and 300-pixels tall, "position" it "left:50%"; and "top:50%;", then, using a negative margin, pull it back half of these respective widths, ergo, "centered" on any window.

Here is an example.<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<html><head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<meta http-equiv="Content-Style-Type" content="text/css" />

<meta http-equiv="Content-Script-Type" content="text/javascript" />

<title></title>

<style type="text/css">

* {border:0; padding:0; margin:0;}

body {height:100%;} /*
IMPORTANT, -need this for IE to work */

</style>

<script type="text/javascript"><!--

// -->

</script>

</head>

<body>


<img alt="image: horizontally and vertically centered" src="images'picture.jpg" style="[B]position: relative; top:50%; left:50%; margin-left:-250px; margin-top:-150px;[/B] [U]width:[B]504[/B]px; height:[B]304[/B]px;[/U] border:3px double black;" />

</body>

</html>[/QUOTE]
×

Success!

Help @shahiz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...