HTML Tutorial


 /help/HTML Help Forum   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
Exact positioning an image atop background/div
Post new topic   Reply to topic    HTML Help Forum -> General HTML
View previous topic :: View next topic  
Author Message
griebs



Joined: 05 Jul 2009
Posts: 3

PostPosted: Sun Jul 05, 2009 4:11 pm     Exact positioning an image atop background/div Reply with quote

For the life of me I cannot get a seemingly simple task to work:

I have 'bg.gif' which is 780x460 (small filesize tho). I would like it centered with a 5px border. I can do this no problem two different ways: centering a table and centering a background (in which case I think I'd have to add the border in photoshop).

The problem is that I cannot position "Image1.gif" or "Image2.gif"..etc where I want them on top of the background image without them jumping all over the place when I change monitor res.
I have tried absolute, relative positioning, padding, margin, V space, H space, even nesting Image1.gif all to no avail. The images do not move in respect to the bg as it self-centers but to the frameset.

Let me know if seeing code will help-- I've got several versions running comparatively complicated Javascripting for fading, swap image etc (work just fine) that I can cut out to get to the main code, just thought there might be a forehead smacking code you genies could come up with right away. Much obliged--
PayneLess Designs



Joined: 28 Feb 2007
Posts: 4289
Location: MS

PostPosted: Sun Jul 05, 2009 4:53 pm     Reply with quote

Try setting the image as the bg image of a div containter. Then set the color you want to use as the five pixel border. Something like this:
Code:
<div style="width: 780px; height: 460px; border: 5px solid #0f0; background: #f00 url(bg.gif) no-repeat center scroll;"></div>
If you need the div container also centered, then add: margin: 0 auto;

Set #f00 as your preferred bg color if you want one. Otherwise, remove the hex color code.
griebs



Joined: 05 Jul 2009
Posts: 3

PostPosted: Sun Jul 05, 2009 5:17 pm     Reply with quote

That's it?! I was using dreamweaver and positioning WIS (what I saw) only WIS was not WIG.

Instead I used pure coding:
Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<div style="width: 780px; height: 460px; border: 5px solid #0f0; background: #f00 url(media/theshirtm.gif) no-repeat center scroll; margin: 0 auto;"><img src="shirt-white.gif" width="254" height="277"/></div>
</head>

<body>
</body>
</html>


Essentially copying what you told me and including the image source inside the div container. Thanks so much!
PayneLess Designs



Joined: 28 Feb 2007
Posts: 4289
Location: MS

PostPosted: Sun Jul 05, 2009 6:35 pm     Reply with quote

You're very welcome. Glad the code was what you needed. Thanks for using HTMLCodeTutorial.com.
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum -> General HTML All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
DARFUR
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial