Scripts Needed

He has: 183 posts

Joined: Nov 2003

Hi everyone.
Does anyone now what the code is to enbed an image in to a table and center it?

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

in the head section of your html page:

<style>
.TdImage
{
text-align:center;
}
</style>
'

in the body section of your html page:

<table width="100%">
<tr>
<td class="TdImage">
<img src="YourSource">
</td>
</tr>
</table>
'

Hope that helps Smiling

Shakespeare: onclick || !(onclick)

He has: 183 posts

Joined: Nov 2003

Thanks mate, just what i needed!!!!

He has: 183 posts

Joined: Nov 2003

Sorry mate, i tryed that code but does that only inserts an image in to a table cell. I need mine to be a background image, embed so if i put loads of text the image if it was small would stay in the same place, in the middle. Is that that code what you give me, or is it other one?

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

Oh, in that case replace that code in your head section with this:

<style>
.TdImage
{
background-image:url('YourSource');
}
</style>
'

and replace the body part with this:

<table width="100%">
<tr>
<td class="TdImage">
YourText Yada Yada Master Yoda
</td>
</tr>
</table>
'

[edit: I'm not sure on the center aligment on background images, maybe someone else?]

Shakespeare: onclick || !(onclick)

He has: 183 posts

Joined: Nov 2003

I can make a background image in my main page center [bgproperties=center] but when i insert that in to my cell background it dont work.

I can already insert a background in to a table, (Dreamweaver does that part for me anyway) just the aligment part i cant do, but it would look really good when done.

Thanks for your help

Busy's picture

He has: 6,151 posts

Joined: May 2001

bgpropeties is an IE body tag

If you have a background image in a table, it will repeat (same as a page background) unless you tell it not to, if you want the image to sit in a table cell (td) then it's totally different, can use align="center" and valign="middle" but the image has to be an image and not a background (alignments don't work on backgrounds - nothing does).
If you just want the image in the middle of the screen (no table) then you use CSS

HTML and/or CSS will do what you want, but need more info by the sounds of it

you want to center the image or table, how many cells does the table have, is the image to be background on all cells ... ?

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

The CSS for it:

.table-with-image {
background-image:url(../images/img.gif);
background-position:center center;
/*The width of the height of the table ould be anything, these are just an example*/
width:100px;
height:100px;
/*To center the table itself...*/
position:relative;
margin:0px auto 0px auto;
/*IE "hack" to center the table*/
display:block;
text-align:center;
}

HTML:

nbsp;

That what you were looking for?

He has: 183 posts

Joined: Nov 2003

I'm having problems with the CSS (Oh and Thanks for that). I'm using Dreamweaver but when i apply a CSS sheet it seem to only put apart of the image on.

Do you no what the problem is?? Do you have a code what i can just cut and paste. all i need is a table (1 row and 1 col) with and image which stays in the middle and does not scroll.

I think the above will work and is what i want, but i just cant get it to work.

He has: 183 posts

Joined: Nov 2003

If i wanted this table background to be fix so when more text is added the image will stay in the same place. What would i have to add to the code above?

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

nothing. The background attribute of the td cell in HTML 4.x affixes the background image in the top left.

He has: 183 posts

Joined: Nov 2003

so how do i get a single image in the table background to stay in the same place (no-repeat) in the middle???

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

You learn CSS and follow Renegade's advice. Smiling

He has: 183 posts

Joined: Nov 2003

Done that, i have learnt CSS. Just that when i did it keep it in the middle, but it only showd part of the picture and when enterd a new line to place next it just repeated it self again with only part of the picture.

Thats why i'm asking for help.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

show your work, then. provide an url for us to use to see what you're doing and where you're going wrong. troubleshooting blind is difficult and annoying.

He has: 4 posts

Joined: Nov 2003

yes i agree. if you show us what your problem is, rather then describing it, i am sure we can help you.

please stop wasting time trying to explain it. just find a space in the World Wide Web and give us the URL.

--
TS
giggledesign.com

---
TS
giggledesign.com

He has: 183 posts

Joined: Nov 2003

Sorry Suzanne. Me doing a 14hour shift and i'm tried. I have created the page for you to look at. Thank you for doing this X

riponcollege.co.uk/help.htm

The Webmistress's picture

She has: 5,586 posts

Joined: Feb 2001

On that page the table is calling a class that isn't in your stylesheet

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Center Background Image in Table</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.unnamed1 {
background-image: url(http://www.riponcollege.co.uk/Images/image010.jpg);
background-repeat: no-repeat;
background-position: center center;
width: 300px;
height: 300px;
border: 1px solid blue;
}
</style>
</head>

<body>
<table class="unnamed1">
<tr>
<td>
<p>Bunch of text.</p>
<p>Bunch of text.</p>
<p>Bunch of text.</p>
<p>Bunch of text.</p>
<p>Bunch of text.</p>
<p>Bunch of text.</p>
<p>Bunch of text.</p>
<p>Bunch of text.</p>
<p>Bunch of text.</p>
<p>Bunch of text.</p>
<p>Bunch of text.</p>
<p>Bunch of text.</p>
<p>Bunch of text.</p>
</td>
</tr>
</table>

</body>
</html>
'

He has: 183 posts

Joined: Nov 2003

Nice one, i o you one, no i o u more then just one. Thank you so ever so much. Smiling

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

FWIW, I'm going to use you as an example of why a concrete sample yields better and faster results than hypothetical questions... Wink

He has: 183 posts

Joined: Nov 2003

I i'm sorry about that. I have learnt my lesson!!!!!

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

a dozen lashes with a wet noodle for you, then. Wink

He has: 183 posts

Joined: Nov 2003

Sticking out tongue Laughing out loud Sticking out tongue

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

WTH? A wet noodle? Well thats a new one... :S

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

You meant to say you've been eating dry noodles all your life? Wink

My, aren't we getting off-topic now or what. Roll eyes

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

I'm not saying that, it just...lashes with a wet noodle? ...never heard that before... lol

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Really? Wow. I've heard that my whole life, I think -- 20 lashes with a wet noodle. Sort of a light-hearted sense of self-flagellation out of guilt for an error, originally, apparently started by Ann Landers, Advice Columnist, sister of Dear Abby. I've co-opted it as a punishment when I don't think a real punishment is required at all, to say, hey, don't sweat it, it happens to us all.

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

Ahh, well there you go, yet another saying for me to use Laughing out loud

He has: 4 posts

Joined: Nov 2003

whoops, seems i missed a page!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.