Why Cant i center

This is a discussion on "Why Cant i center" within the Web Page Design section. This forum, and the thread "Why Cant i center are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jun 20th, 2007, 18:01
New Member
Join Date: Jun 2007
Location: Berwick, england
Age: 17
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Why Cant i center

ok, i have made myself a site, its a portfolio site Link and im wondering how do i center it, its made using AP Divs as i needed layers to create the scroll bar in the middle.

anyways, i've tryed a variaty of ways:

Quote:
<script language = “JavaScript”>
<!-- Hide from non-JavaScript Aware Browsers
function centerLayout()
{
var layoutwidth = 665 // set the width of the page here

if (navigator.appName == 'Netscape') {
var bodyWidth = self.innerWidth;
var theOffset = ((bodyWidth - layoutWidth)/2) - 10;
if (theOffset > 0)
document.layers['LayoutLYR'].left = theOffset;
} else {
var bodyWidth = document.body.offsetWidth;
var theOffset = ((bodyWidth - layoutWidth)/2) - 10;
if (theOffset > 0)
document.all.tags('DIV')['Layout.LYR'].style.left=theOffset;
}
// End Hiding -->
</script>
^ adding the "onLoad = centerLayout() onResize = centerLayout()" in teh appropriate place aswel, But this didnt work.

i've also tryed the usual <center> and the <div align="center">



but for some unbeknown reason i cant center the site - any help is appreciated.


Below is my code for my site (without any referals to center)

Quote:
<html>

<head>
<title>CuLTz :: Home</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type='text/css'>

body { background-color=#343434; }

body { align='center' }

.style1 {
font-size: 12px
}
a:link {
color: #990000;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #FFFFFF;
}
a:hover {
text-decoration: underline;
color: #FF0000;
}
a:active {
text-decoration: none;
}


</style>

</head>



<body bgcolor="#343434" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad = centerLayout() onResize = centerLayout()>


<div id="apDiv1" style="position: absolute; left: 41px; top: 0px; width: 665px; height: 164px; z-index: 9"><img src="images/Top.jpg" alt="" width="665" height="164"></div>

<div id="apDiv2" style="position: absolute; left: 41px; top: 164px; width: 154px; height: 584px; z-index: 2; vertical-align: middle"><img src="images/Left.jpg" alt="" width="154" height="584"></div>

<div id="apDiv3" style="position: absolute; left: 195px; top: 164px; width: 105px; height: 59px; z-index: 3"><a href="Home.html"><img src="images/Home.jpg" alt="" width="105" height="59" border="0"></a></div>

<div id="apDiv4" style="position: absolute; left: 300px; top: 164px; width: 129px; height: 59px; z-index: 4"><a href="Portfolio.html"><img src="images/Portfolio.jpg" alt="" width="129" height="59" border="0"></a></div>

<div id="apDiv5" style="position: absolute; left: 429px; top: 164px; width: 116px; height: 59px; z-index: 5"><a href="Contact.html"><img src="images/Contact.jpg" alt="" width="116" height="59" border="0"></a></div>

<div id="apDiv6" style="position: absolute; left: 545px; top: 164px; width: 161px; height: 584px; z-index: 6; vertical-align: middle"><img src="images/Right.jpg" alt="" width="161" height="584"></div>

<span id="apDiv7" style="position: absolute; left: 195px; top: 223px; width: 350px; height: 371px; z-index: 0; background: #F39322; overflow: auto; background-image: url(images/Main.jpg); layer-background-image: url(images/Main.jpg); border: 1px none #000000;">

<center><p class="style1"><b>.:: <u>W e l c o m e</u> ::.</b></p></center>

<p class="style1">&nbsp;</p>

<p class="style1"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur massa diam, tristique ac, elementum at, pellentesque quis, urna. Donec ultricies, mauris id ullamcorper tincidunt, nulla justo vehicula nisi, at aliquet justo quam eget ante. </P>

<p class="style1">Phasellus eleifend tortor turpis vel nulla. Phasellus id urna. Morbi sed arcu dignissim est auctor dignissim. Aenean orci. Aenean rhoncus orci in nulla. Ut consequat. Cras dapibus justo in purus. Nam sed urna. Nullam eget tellus eu ante pulvinar commodo. Sed imperdiet lectus ac nibh. Vivamus vitae tellus. Mauris velit mauris, luctus a, eleifend sit amet, mattis quis, nulla. </p>

<p align="center" class="style1">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur massa diam, tristique ac, elementum at, pellentesque quis, urna. Donec ultricies, mauris id ullamcorper tincidunt, nulla justo vehicula nisi, at aliquet justo quam eget ante. </p>

<p align="center" class="style1">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur massa diam, tristique ac, elementum at, pellentesque quis, urna. Donec ultricies, mauris id ullamcorper tincidunt, nulla justo vehicula nisi, at aliquet justo quam eget ante. </p>

<p class="style1"> Phasellus eleifend tortor turpis vel nulla. Phasellus id urna. Morbi sed arcu dignissim est auctor dignissim. Aenean orci. Aenean rhoncus orci in nulla. Ut consequat. Cras dapibus justo in purus. Nam sed urna. Nullam eget tellus eu ante pulvinar commodo. Sed imperdiet lectus ac nibh. Vivamus vitae tellus. Mauris velit mauris, luctus a, eleifend sit amet, mattis quis, nulla. </p>

<p class="style1">Phasellus eleifend tortor turpis vel nulla. Phasellus id urna. Morbi sed arcu dignissim est auctor dignissim. Aenean orci. Aenean rhoncus orci in nulla. Ut consequat. Cras dapibus justo in purus. Nam sed urna. Nullam eget tellus eu ante pulvinar commodo. Sed imperdiet lectus ac nibh. Vivamus vitae tellus. Mauris velit mauris, luctus a, eleifend sit amet, mattis quis, nulla. Phasellus eleifend tortor turpis vel nulla. Phasellus id urna. Morbi sed arcu dignissim est auctor dignissim. Aenean orci. Aenean rhoncus orci in nulla. Ut consequat. Cras dapibus justo in purus. Nam sed urna. Nullam eget tellus eu ante pulvinar commodo. Sed imperdiet lectus ac nibh. Vivamus vitae tellus. Mauris velit mauris, luctus a, eleifend sit amet, mattis quis, nulla. </p>

<p class="style1">&nbsp;</p>

<span class="style1">Phasellus eleifend tortor turpis vel nulla. Phasellus id urna. Morbi sed arcu dignissim est auctor dignissim. Aenean orci. Aenean rhoncus orci in nulla. Ut consequat. Cras dapibus justo in purus. Nam sed urna. Nullam eget tellus eu ante pulvinar commodo. Sed imperdiet lectus ac nibh. Vivamus vitae tellus. Mauris velit mauris, luctus a, eleifend sit amet, mattis quis, nulla. </span><span class="style1">Phasellus eleifend tortor turpis vel nulla. Phasellus id urna. Morbi sed arcu dignissim est auctor dignissim. Aenean orci. Aenean rhoncus orci in nulla. Ut consequat. Cras dapibus justo in purus. Nam sed urna. Nullam eget tellus eu ante pulvinar commodo. Sed imperdiet lectus ac nibh. Vivamus vitae tellus. Mauris velit mauris, luctus a, eleifend sit amet, mattis quis, nulla. </span><span class="style1">Phasellus eleifend tortor turpis vel nulla. Phasellus id urna. Morbi sed arcu dignissim est auctor dignissim. Aenean orci. Aenean rhoncus orci in nulla. Ut consequat. Cras dapibus justo in purus. Nam sed urna. Nullam eget tellus eu ante pulvinar commodo. Sed imperdiet lectus ac nibh. Vivamus vitae tellus. Mauris velit mauris, luctus a, eleifend sit amet, mattis quis, nulla.</span></span>

<div id="apDiv8" style="position: absolute; left: 195px; top: 594px; width: 350px; height: 154px; z-index: 8" onLoad = centerLayout() onResize = centerLayout()><img src="images/Bottom.jpg" alt="" width="350" height="154"></div>


</body>


</html>
any ideas?
Reply With Quote

  #2 (permalink)  
Old Jun 20th, 2007, 18:13
karinne's Avatar
SuperMember

SuperMember
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why Cant i center

wow ... you don't need JS to create a "scrollbox" you know

See the CSS Beginner FAQ - How to get a scrollable area on my page

Then ... remove all the position: absolute;

And here's how to center you site:
How to center your site horizontally
body can be used to style too!
Reply With Quote
  #3 (permalink)  
Old Jun 20th, 2007, 18:15
SuperMember

SuperMember
Join Date: Sep 2006
Location: Pink House
Posts: 3,946
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why Cant i center

Well I would put all your html into a div called wrap.

css
Code: Select all
#wrap {
    margin:0 auto;
    width: whateverpx;
}
You are probably going to have to eliminate all the absolute positioning however.
Absolute positioning will override the code I gave you above.
Reply With Quote
  #4 (permalink)  
Old Jun 20th, 2007, 18:27
New Member
Join Date: Jun 2007
Location: Berwick, england
Age: 17
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why Cant i center

edit,

Karrine - i used JS to try and center it not to create a scrollable box

and sorry guys but i dont understand how to use the other methods yous said to try and center it, reason being, how can i remove the ABSOLOUTE; from AP Divs (absoloute positioning) - it just screws up my page unfortunatle.

any nooooooooooob guides on how to center Ap divs easily ?

sorry.

Last edited by Innes; Jun 20th, 2007 at 18:44.
Reply With Quote
  #5 (permalink)  
Old Jun 20th, 2007, 18:49
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Posts: 2,020
Blog Entries: 1
Thanks: 0
Thanked 33 Times in 33 Posts
Re: Why Cant i center

Basically to center a layout horizontally all you need is a width and margin:0 auto; You certainly do not need javascript to handle this. Also you need to deal with people with s disabled, if you rely on js to display your page you will alienate a bunch of users.

If you need to do both vertical and horizontal centering then this example will show you how to do it with css.

http://www.newguyinennis.com/samples...centering.html

Code: Select all
body { background-color=#343434; }
 
body { align='center' }
The above code is invalid. The below code would be correct.

Code: Select all
body {
text-align:center;
background-color:#343434;
}
Looks like you are using some WYSIWYG editor which may be your problem. I would avoid using whatever you are to automatically generate your code.
__________________
I hate IE 6. Just sayin....
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)

Last edited by moojoo; Jun 20th, 2007 at 18:55.
Reply With Quote
  #6 (permalink)  
Old Jun 20th, 2007, 19:03
New Member
Join Date: Jun 2007
Location: Berwick, england
Age: 17
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why Cant i center

ill give it a wirl and edit my post, and im using Adobe Dreamweaver CS3, i prefered 8.0 tbh but this will do the now.


Edit - nope, it didnt center, its still at the left.

But i cant see how i can remove absoloute positioning from Absoloute Positioning divs. =(

Last edited by Innes; Jun 20th, 2007 at 19:06.
Reply With Quote
  #7 (permalink)  
Old Jun 20th, 2007, 19:13
karinne's Avatar
SuperMember

SuperMember
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Why Cant i center

div don't have to be absolutely positioned... and they shouldn't ... in this case. Absolute means it's there and stays there. It won't move when the browser is resized.

Start from scratch. Learn CSS and how to create layouts. See moojoo's sig for great examples and also the thread in my sig has a bunch more.
Reply With Quote
  #8 (permalink)  
Old Jun 20th, 2007, 20:37
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Posts: 2,020
Blog Entries: 1
Thanks: 0
Thanked 33 Times in 33 Posts
Re: Why Cant i center

http://www.newguyinennis.com/samples/layouts/ would be the correct url. No direct link from my site heh.
__________________
I hate IE 6. Just sayin....
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Reply With Quote
Reply

Tags
need help

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Div bg images..will not center? jahphill Web Page Design 5 Jun 2nd, 2008 09:03
how can i center this? djcritch Web Page Design 6 Feb 25th, 2008 07:06
center alexgeek Web Page Design 1 Aug 2nd, 2007 03:30
Center a Swf Help?? nutbolt Web Page Design 20 Apr 9th, 2007 10:21
just want to center this ragingmon Web Page Design 9 Dec 29th, 2006 18:07


All times are GMT. The time now is 09:10.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43