There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Web Design & Development
Tag Cloud
access acer asus bios bsod computer crash dns driver drivers error ethernet excel freeze gaming google hard drive hardware hdmi internet laptop mac malware memory monitor motherboard mouse network printer problem ram registry router server slow software sound svchost.exe trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
css centering problem

Reply  
Thread Tools
jtn3833's Avatar
Member with 413 posts.
 
Join Date: Dec 2000
Location: st. louis, mo USA
01-Nov-2009, 06:07 PM #1
css centering problem
I'm relatively new to CSS and I'm using it to perfectly place a few images in relation to each other using the z-index. I have everything where I want them using absolute and relative code I found and barely understand - but I can't get the entire page to center.

I thought it would be easy to put a "wrapper" div around everything and center that but it doesn't work.

I think it has something to do with the images being taken out of the flow by the absolute and relative positioning code. I need them exactly where they are in relation to each other but I'd like to center the entire thing.

code available upon request.
thanks,
JTN
__________________
Dell inspiron 580 | Win7-64 | i5-750 | 4G RAM | GeForce GT240-1Gig
Eriksrocks's Avatar
Computer Specs
Distinguished Member with 2,198 posts.
 
Join Date: Aug 2005
Location: Minnesota
Experience: Advanced
03-Nov-2009, 01:18 AM #2
Try adding "position: relative" to the wrapper div. If that still doesn't work, you're going to have to try using all relative positioning or finding another method to arrange the images how you would like them.

Code would help.
jtn3833's Avatar
Member with 413 posts.
 
Join Date: Dec 2000
Location: st. louis, mo USA
05-Nov-2009, 10:39 AM #3
The "position: relative" didn't work, thanks though.

Here's the HTML:
-------------------------------------------
<div id="wrapper">


<body onload="MM_preloadImages('images/nav/comics2.png','images/nav/games2.png')">
<div id="container-map"><a href="index.html"><img src="images/logo2.png" border="0" class="logo" /></a><img src="images/heros/hero-front.png" border="0" usemap="#Map" class="front" />
<map name="Map" id="Map"><area shape="rect" alt="email us here" coords="225,12,453,30" href="mailto:gerald@bigcitycomix.com" /></map>
<img src="images/heros/hero-back.png" class="back" />
<div class="info-box">

<div align="center">
<table width="695" border="0" cellpadding="10" cellspacing="0">
<tr valign="top">
<td><a href="comix.html" target="_top" onclick="MM_nbGroup('down','group1','Comics','images/nav/comics2.png',1)" onmouseover="MM_nbGroup('over','Comics','images/nav/comics2.png','images/nav/comics2.png',1)" onmouseout="MM_nbGroup('out')"><img src="images/nav/comics1.png" alt="Comics" name="Comics" width="135" height="35" border="0" id="Comics" onload="" /></a></td>
<td><img src="images/nav/map2.png" alt="map to our location" name="map" width="70" height="35" border="0" id="map" onload="" /></td>
<td><a href="games.html" target="_top" onclick="MM_nbGroup('down','group1','games','images/nav/games2.png',1)" onmouseover="MM_nbGroup('over','games','images/nav/games2.png','images/nav/games2.png',1)" onmouseout="MM_nbGroup('out')"><img src="images/nav/games1.png" alt="games &amp; tournament info" name="games" width="401" height="35" border="0" id="games" onload="" /></a></td>
</tr>
<tr valign="top">
<td colspan="3"><div align="center"><iframe width="680" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=big+city+comix+%2B6414 5&amp;sll=38.905194,-94.607799&amp;sspn=0.008282,0.013797&amp;gl=us&amp;ie=UTF8&amp;hq=big+city+ comix&amp;hnear=Kansas+City,+MO+64145&amp;ll=38.926297,-94.599323&amp;spn=0.066246,0.110378&amp;z=13&amp;iwloc=A&amp;cid=1421737790 2084214564&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=big+city+comix+%2B64 145&amp;sll=38.905194,-94.607799&amp;sspn=0.008282,0.013797&amp;gl=us&amp;ie=UTF8&amp;hq=big+city+ comix&amp;hnear=Kansas+City,+MO+64145&amp;ll=38.926297,-94.599323&amp;spn=0.066246,0.110378&amp;z=13&amp;iwloc=A&amp;cid=1421737790 2084214564" style="color:#0000FF;text-align:left">View Larger Map</a></small></td>
</tr>
</table>

</div>

</div>
</div>
-------------------------------------------

Here's the CSS:
-------------------------------------------
@charset "utf-8";
/* CSS Document */

body {
font-family:Arial, Helvetica, sans-serif;
margin: 0px;
padding: 0px;
border: 0px;
background-image:url(../images/background/comic-background.jpg);
}



#wrapper {
width: 960px;
margin: 0 auto 0 auto;
position: relative;

}

br.clear {
clear:both;
}




#container {
width: 945px;
height: 600px;
margin: 0 10px 0 10px;
border: 5px solid black;
}

#container-map {
width: 945px;
height: 875px;
margin: 0 10px 0 10px;
border: 5px solid black;
}

.center {
vertical-align: top;
width: 869px;
margin: 0 0 0 0;
}

#hero-back {
position: relative;
z-index: 10;
width: 1024px;
height: 550px;
margin: 40px auto 0px auto;
}

#hero-front {
position: relative;
z-index: 1;
width: 654px;
height: 473px;
margin: 40px auto 0px auto;
}

#front_box {
position:relative;
display:block;
}

img.front {
position: absolute;
top: 200px;
left: 285px;
}

#logo_box {
position:relative;
display: block;
}

img.logo {
position: absolute;
top: 5px;
left: 35px;
}

#back_box {
position:relative;
display: block;
}

img.back {
position: absolute;
top: 115px;
left: 10px;
z-index: -5;
}

.info-box {
background-color:#FFFF00;
width: 700px;
position: absolute;
top: 350px;
left: 135px;
z-index: 50;
border: 5px solid black;
clear: both;
}

#footer {
position: absolute;
left: 10px;
font-family:Arial, Helvetica, sans-serif;
font-size: 9px;

}
-------------------------------------------

...you can see the site at www.BigCityComix.com

Thanks for your help,
JTN
__________________
Dell inspiron 580 | Win7-64 | i5-750 | 4G RAM | GeForce GT240-1Gig
colinsp's Avatar
Computer Specs
Senior Member with 1,044 posts.
 
Join Date: Sep 2007
Location: Spain
Experience: Adv PC, int HTML, bit PHP
06-Nov-2009, 02:14 AM #4
Looking at your site it takes an age to load with the way that you have your graphics being loaded. You are also using tables in not the recommended way. This is typical of the way that Dreamweaver creates code of this type.

IMHO your best way forward would be to create a gif image that contains all of your page other than the navigation. Create a centred container div with this graphic as the background and then poosition your navigation dive appropriately within this div. The title and location boxes should be part of your gif image.

If you do this it will give you a faster loading page, lose the tables and allow you to position the nav div easily where you want it.
jtn3833's Avatar
Member with 413 posts.
 
Join Date: Dec 2000
Location: st. louis, mo USA
06-Nov-2009, 12:27 PM #5
colinsp - Of course, why didn't I think of making all of the images into one. I was so excited that I finally figured out how to layer images with CSS that it didn't even cross my mind, and it would speed up the page considerably.

My only concerns are:
1- a gif won't give me the image quality I'm looking for along with transparency - maybe I'll make it into a jpg or something.
2- I don't know how to do rollovers with CSS, hence the tables. Can you point out a good website tutorial?

Thanks,
JTN
__________________
Dell inspiron 580 | Win7-64 | i5-750 | 4G RAM | GeForce GT240-1Gig
colinsp's Avatar
Computer Specs
Senior Member with 1,044 posts.
 
Join Date: Sep 2007
Location: Spain
Experience: Adv PC, int HTML, bit PHP
07-Nov-2009, 02:37 AM #6
If a gif won't do what you want try a png it will be smaller than a jpg you want the image to be ideally under about 60k.

As to menu rollover tutorials there are loads of them out there, here's a couple of url's
http://www.cssplay.co.uk/menus/
http://www.chouselive.co.za/tutorial...useover-00.php
http://www.xentrik.net/css/
http://www.webcredible.co.uk/user-fr...ion-menu.shtml
http://css-tricks.com/video-screencasts/

Have a look at those and I am sure you will crack it. But come back if you have any specific issues.
Eriksrocks's Avatar
Computer Specs
Distinguished Member with 2,198 posts.
 
Join Date: Aug 2005
Location: Minnesota
Experience: Advanced
07-Nov-2009, 03:00 AM #7
Yes, colinsp's idea is better than trying to deal with absolute positioning and tables.
jtn3833's Avatar
Member with 413 posts.
 
Join Date: Dec 2000
Location: st. louis, mo USA
09-Nov-2009, 03:56 PM #8
Okay, I've almost got it done and it loads soo much faster. You can see it here.

I currently have 2 problems:

1- Before I used Dreamweaver's Image Mapping to make the email address of an image clickable, but that's no longer an option because it's a background image. I've looked and cannot find a way to put coordinates or something to make a section of background clickable for a mailto tag. My only thought is to put a transparent png or something directly in front of the email address and have that be the mailto button. Is there an easier way?

2- I used the first in the list of tutorials you posted to do css rollovers (thanks for that), so I'm not sure if this is a problem or not but the only way I was able to align the nav buttons horizontally was by using a table. Without the table they stair stepped down and I'm pretty sure it's because of the <p> tag.

Thanks for you help, I really appreciate it,
JTN
__________________
Dell inspiron 580 | Win7-64 | i5-750 | 4G RAM | GeForce GT240-1Gig
colinsp's Avatar
Computer Specs
Senior Member with 1,044 posts.
 
Join Date: Sep 2007
Location: Spain
Experience: Adv PC, int HTML, bit PHP
10-Nov-2009, 02:28 AM #9
Hey, that's great it loads so much faster and looks just as good as your original.

1: The transparent png is probably the best idea unless someone comes up with a better one.

2: have a look at this video I think that it will help with the rollovers.
jtn3833's Avatar
Member with 413 posts.
 
Join Date: Dec 2000
Location: st. louis, mo USA
10-Nov-2009, 11:46 PM #10
I haven't worked on the rollovers yet because I had an idea...

Why does the large image need to be a background image? Using CSS I should be able to position the nav bar on top of the heroes image even if it's a real image and not a background. As a 'real' image I would be able to image map it for the email address button, but for some reason it's not working.

as seen here, you need to scroll down to find the nav.

I have the z-index of the nav set to 50, so does z-index only work over a background image?

What is the advantage of having everything as a background image in div's? Does it load faster or is it just so you can z-index things on top of it?

Thanks for your help,
JTN
__________________
Dell inspiron 580 | Win7-64 | i5-750 | 4G RAM | GeForce GT240-1Gig
colinsp's Avatar
Computer Specs
Senior Member with 1,044 posts.
 
Join Date: Sep 2007
Location: Spain
Experience: Adv PC, int HTML, bit PHP
11-Nov-2009, 02:51 AM #11
I have never used an image map so I am not certain but I suspect you are falling foul of the css box model. Your page does seem to take longer to load now you have made this change over how it loaded when it was a background image. If you don't want to go the png route you could make the contact box a separate div with the background all except the email address and then make the email address a mailto: and then position the vav div below it.
jtn3833's Avatar
Member with 413 posts.
 
Join Date: Dec 2000
Location: st. louis, mo USA
30-Nov-2009, 02:52 PM #12
Okay, I've almost got it (see it here). Since I needed an image not in the background for the image map of the email address I decided to just use the bottom half of the title area with the hours & contact info on it.

I also resized a few things and moved the navigation.

The main background is all one image now, except for the bottom. I put the superheroes feet in as a png directly below the main image jpg to give it a little dimension.

I'm very close now, but I've run into a strange snag. on my new nav bar for some reason the "Map" button only shows up in IE, Firefox completely ignores it and I can't see a difference in the coding.

HTML-------------------------------
<!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>Big City Comix &amp; Games - Kansas City's Premiere Comic &amp; Game Store</title>
<link href="css/bcc.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div id="container-white">
<div id="container2">

<div class="email">
<img src="images/nav-11-23/header-hours.png" border="0" usemap="#Map" />
<map name="Map" id="Map"><area shape="rect" coords="181,28,406,49" href="Gerald@BigCityComix.com" alt="email me here" />
</map></div>

<div class="nav2">

<p class="image-swap-comics"> <a href="#nogo"><em></em></a> </p>
<p class="image-swap-map"> <a href="#nogo"><em></em></a> </p>
<p class="image-swap-games"> <a href="#nogo"><em></em></a> </p>

</div>

</div>
<div id="heroes-bottom"> <img src="images/heroes/heros_bottom.png" /></div>
</div>

</body>
</html>

CSS (this needs to be cleaned up, sorry for the mess)-------------------------------
@charset "utf-8";
/* CSS Document */

body {
font-family:Arial, Helvetica, sans-serif;
margin: 0px;
padding: 0px;
border: 0px;
background-image:url(../images/background/comic-background.jpg);
}


#wrapper {
width: 960px;
margin: 0 auto 0 auto;
position: relative;

}

br.clear {
clear:both;
}

#heroes-bottom {
width: 938px;
height: 70px;
background-image:url(../images/heroes/heros_bottom.png);
position: relative;
left: 5px;
top: 0px;

}

#container2 {
width: 938px;
height: 615px;
margin: 0 auto 0 auto;
border-top: 5px solid black;
border-left: 5px solid black;
border-right: 5px solid black;
background-image:url(../images/heroes/heroes-top.jpg);
background-repeat: no-repeat;
}

#container-white {
margin: 5px auto 0 auto;
width: 942px;
height: auto;

}

/*COMICS BUTTON*/
.image-swap-comics {
width: 85px;
height: 15px;
position: relative;
padding: 0;
margin: 0;
line-height: 85px;
vertical-align: top;
text-align: center;
}

.image-swap-comics em {
display: block;
width: 85px;
height: 15px;
position: absolute;
top: 0;
left: 0;
background: url(../images/nav-11-23/comics.png);
background-position: left;
}

.image-swap-comics a:hover em {
background: url(../images/nav-11-23/comics.png);
background-position: right;
}


/*TOURNAMENT & GAMES BUTTON*/
.image-swap-games {
width: 151px;
height: 38px;
position: relative;
padding: 0;
margin: 0;
line-height: 151px;
vertical-align: top;
text-align: center;
}

.image-swap-games em {
display: block;
width: 151px;
height: 38px;
position: absolute;
top: 25px;
left: 0;
background: url(../images/nav-11-23/games.png);
background-position: left;
}

.image-swap-games a:hover em {
background: url(../images/nav-11-23/games.png;
background-position: right;
}

/*MAP BUTTON*/
.image-swap-map {
width: 43px;
height: 15px;
position: relative;
padding: 0;
margin: 0;
line-height: 43px;
vertical-align: top;
text-align: center;
}

.image-swap-map em {
display: block;
width: 43px;
height: 15px;
position: absolute;
top: 15px;
left: 0;
background: url(../images/nav-11-23/map.png);
background-position: left;
}

.image-swap-map a:hover em {
background: url(../images/nav-11-23/map.png);
background-position: right;
}

.nav {
background-color:#FFF100;
width: 700px;
height: auto;
position: relative;
top: 300px;
left: 119px;
z-index: 50;
border: 5px solid black;
clear: both;
}

.nav2 {
width: 150px;
height: auto;
position: relative;
top: 115px;
left: 100px;
z-index: 50;
clear: both;
}


#container {
width: 943px;
height: 690px;
margin: 0 10px 0 10px;
border: 5px solid black;
}

#container-map {
width: 945px;
height: 875px;
margin: 0 10px 0 10px;
border: 5px solid black;
}

.center {
vertical-align: top;
width: 869px;
margin: 0 0 0 0;
}

#hero-back {
position: relative;
z-index: 10;
width: 1024px;
height: 550px;
margin: 40px auto 0px auto;
}

#hero-front {
position: relative;
z-index: 1;
width: 654px;
height: 473px;
margin: 40px auto 0px auto;
}

#front_box {
position:relative;
display:block;
}

img.front {
position: absolute;
top: 200px;
left: 285px;
}

#logo_box {
position:relative;
display: block;
}

img.logo {
position: absolute;
top: 5px;
left: 35px;
}

#back_box {
position:relative;
display: block;
}

img.back {
position: absolute;
top: 115px;
left: 10px;
z-index: -5;
}

.info-box {
background-color:#FFFF00;
width: 700px;
position: absolute;
top: 350px;
left: 135px;
z-index: 50;
border: 5px solid black;
clear: both;
}



.email {
width: 611px;
height: 76px;
position: relative;
top: 73px;
left: 306px;
}

#footer {
position: absolute;
left: 10px;
font-family:Arial, Helvetica, sans-serif;
font-size: 9px;

}

Any ideas on the strange "Map" button issue?

Thanks,
JTN
__________________
Dell inspiron 580 | Win7-64 | i5-750 | 4G RAM | GeForce GT240-1Gig
tex0gen's Avatar
Computer Specs
Member with 282 posts.
 
Join Date: Jun 2007
Location: Ashford, Kent
Experience: WebDev
01-Dec-2009, 09:35 AM #13
add the following to your CSS:

Code:
* {
     margin: 0 auto;
     padding: 0;
}

html {
     text-align: center;
}


This will center your layouts in both IE and FF.
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 10:26 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.