Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hey. Ive searched the archives and

Status
Not open for further replies.

gwar2k1

Programmer
Apr 17, 2003
387
GB
Hey. Ive searched the archives and checked the FAQs, I cant find one that helps. But maybe Im just unable to spot a good answer...

I would like to center a div object so it'll always be in the middle when the page resizes. If I was guaranteed that every user had 1024 x 768 resolution, it wouldn't be a problem but obviously nothing's easy.

I currently use the code below, though... it doesnt work at all. Everything just shifts to the left as if the center tag doesn't exist.

<center>
<div class=&quot;everything&quot;>

<div class=&quot;banner&quot;>

<div class=&quot;topleft&quot;><img src=&quot;topleft.png&quot; width=&quot;155&quot; height=&quot;47&quot;><div>
<div class=&quot;middle&quot;></div>
<div class=&quot;topright&quot;><img src=&quot;topright.png&quot; width=&quot;320&quot; height=&quot;37&quot;></div>
<div class=&quot;navigation&quot;><img src=&quot;navigation.png&quot; width=&quot;760&quot; height=&quot;29&quot;></div>
<div class=&quot;corporate&quot;><img src=&quot;corporate.png&quot; width=&quot;760&quot; height=&quot;22&quot;></div>
<input class=&quot;search&quot;>
<select class=&quot;searcharea&quot;>

</div>

</div>
</center>

I'm using IE 6.1, notepad and a stylesheet:

div.everything {
height: 822;
width: 760;
}

That did have a position: absolute and x,y coordinates but I removed them because I don't want it to be resolution specific.



~*Gwar3k1*~
&quot;To the pressure, everything's just like: an illusion. I'll be losing you before long...&quot;
 
Thats what I thought ^^ stupid MS. But a refresh doesnt work either :(

~*Gwar3k1*~
&quot;To the pressure, everything's just like: an illusion. I'll be losing you before long...&quot;
 
In place of your <center> tag, try this:

<div align=&quot;center&quot;>
.
. your code between these tags
.
</div>

Paul Wesson, Programmer/Analyst
 
No joy :(
Is it browser specific? I read somewhere DIV aligns were stopped in like IE 5 and NS4 or something?


~*Gwar3k1*~
&quot;To the pressure, everything's just like: an illusion. I'll be losing you before long...&quot;
 
------------
Style sheet:
------------

body {
background-image: url(background.png);
color: #ffffff;
font-family: Arial;
font-size: 10pt;
}


div.everything {
height: 822;
width: 760;
}


div.banner {
position: absolute;
top: 0;
left: 0;
height: 98;
width: 760;
}
div.topleft {
position: absolute;
top: 13;
left: 0;
height: 47;
width: 155;
}
div.topmiddle {
position: absolute;
top: 27;
left: 155;
background-image: url(filler.png);
height: 20;
width: 293;
}
div.topright {
position: absolute;
top: 10;
left: 440;
height: 37;
width: 320;
}
div.navigation {
position: absolute;
top: 47;
left: 0;
height: 29;
width: 760;
}
div.corporate {
position: absolute;
top: 76;
left: 0;
height: 22;
width: 760;
}
div.memboptions {
position: absolute;
top: 98;
left: 0;
height: 18;
width: 760;
background-image: url(statusbg.png);
}

div.right {
position: absolute;
top: 98;
left: 552;
}
div.memblogin {
position: absolute;
top: 18;
left: 0;
height: 134;
width: 184;
background-image: url(loginbg.png);
}
div.membbenefit {
position: absolute;
top: 152;
left: 0;
height: 211;
width: 184;
background-image: url(benefits.png);
}


div.main {
position: absolute;
top: 116;
left: 0;
height: 668;
width: 760;
z-index: -1
}
div.upperleft {
position: absolute;
top: 0;
left: 0;
height: 106;
width: 15;
}
div.upperright {
position: absolute;
top: 0;
left: 745;
height: 106;
width: 15;
}
div.middle {
position: absolute;
top: 0;
left: 9;
height: 667;
width: 742;
z-index: -1;
background-image: url(middlebg.png);
background-reapeat: repeat-y;
}
div.lowerleft {
position: absolute;
top: 521;
left: 0;
height: 146;
width: 15;
}
div.lowerright {
position: absolute;
top: 521;
left: 736;
height: 146;
width: 15;
}

div.mainimage {
position: absolute;
top: 125;
left: 24;
height: 116;
width: 519;
}


img {
border: 0;
}
a {
color: #a8d2fd;
text-decoration: none;
font-weight: bold;
}
input,select {
font-family: Veranda;
font-size: 10px;
color: #330066;
background-color: #ffffff;
border: 1px solid #999999;
width: 110;
height: 18;
}
.search {
position: absolute;
top: 18;
left: 500;
}
.searcharea {
position: absolute;
top: 18;
left: 620;
}

----
HTML
----

<html>

<head>
<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;layout.css&quot;>
</head>

<body>


<div class=&quot;everything&quot; align=&quot;center&quot;>

<div class=&quot;banner&quot;>

<div class=&quot;topleft&quot;><img src=&quot;nintendo.png&quot; width=&quot;155&quot; height=&quot;47&quot;><div>
<div class=&quot;topmiddle&quot;></div>
<div class=&quot;topright&quot;><img src=&quot;topright.png&quot; width=&quot;320&quot; height=&quot;37&quot;></div>
<div class=&quot;navigation&quot;><img src=&quot;navigation.png&quot; width=&quot;760&quot; height=&quot;29&quot;></div>
<div class=&quot;corporate&quot;><img src=&quot;corporate.png&quot; width=&quot;760&quot; height=&quot;22&quot;></div>
<div class=&quot;memboptions&quot;></div>
<input class=&quot;search&quot;>
<select class=&quot;searcharea&quot;>

</div>

<div class=&quot;right&quot;>

<div class=&quot;memblogin&quot;></div>
<div class=&quot;membbenefit&quot;></div>

</div>

<div class=&quot;main&quot;>

<div class=&quot;upperleft&quot;><img src=&quot;upperleft.png&quot;></div>
<div class=&quot;upperright&quot;><img src=&quot;upperright.png&quot;></div>
<div class=&quot;middle&quot;></div>
<div class=&quot;lowerleft&quot;><img src=&quot;lowerleft.png&quot;></div>
<div class=&quot;lowerright&quot;><img src=&quot;lowerright.png&quot;></div>

</div>

<div class=&quot;mainimage&quot;><img src=&quot;gbaspbanner.png&quot;></div>

</div>
<center>

</body>

</html>



-----------------

Thats everything. Ive noticed another problem. It doesnt display anything but the div class=&quot;border&quot; in an IE window, though in MS Frontpage it shows everything. Im only using frontpage to test how it looks, im using notepad to make it.

~*Gwar3k1*~
&quot;To the pressure, everything's just like: an illusion. I'll be losing you before long...&quot;
 
Oh...that's totally your problem...you're using position:absolute; for practically every class, which overrides the center....Use the <center> tag like I said instead of 'align=&quot;center&quot;', since that's depricated.

After that, go through the stylesheet and make everything relative where it says absolute. You can then re-calculate the positions.

Rick

-----------------------------------------------------------
RISTMO Designs
Arab Church
Reference Guides
 
relative is to the screen not the parent element right?

~*Gwar3k1*~
&quot;To the pressure, everything's just like: an illusion. I'll be losing you before long...&quot;
 
are you sure cause Im using absolute with a lot of 0s and it works to the parent element. this is why im asking lol. i get confused between the two

~*Gwar3k1*~
&quot;To the pressure, everything's just like: an illusion. I'll be losing you before long...&quot;
 
Yes--I'm sure. Actually, that is why your page doesn't work. Your parent element (the first div) is centered, yet because you use absolute positioning, the sub-elements appear aligned to the left of the browser. Also, &quot;absolute&quot; means regardless of everything else....position:absolute;left:30px; means that regardless of the rest of the page, put that element 30px from the left of the page....even if it was in a div that was centered. The &quot;absolute&quot; overrides the <center>. That's why your page doesn't work. If you use &quot;relative&quot;, instead, and find out the right values to put them back in their right places, you can do anything you want to the parent div, and the innerhtml will adjust to stay in the same positions relative to each other, NOT the page, like they're doing now.

Did that make sence?

Rick

-----------------------------------------------------------
RISTMO Designs
Arab Church
Reference Guides
 
It did... yeah ;) No it did. Ive managed to do it my making only the main div relative. So I dunno if this blows your idea of CSS wide open or if you think (as I do) I have magical powers and code fears me for said reason.

Yes, Im crazy =D

Cheerz

~*Gwar3k1*~
&quot;To the pressure, everything's just like: an illusion. I'll be losing you before long...&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top