Irish SEO,  Marketing & Webmaster Discussion

 

Problem with centering a layout-relative to browser window size using CSS

This is a discussion on Problem with centering a layout-relative to browser window size using CSS within the HTML Basics forums, part of the Coding Help category; Hi all I'm having trouble centering a layout. I'm using Dreamweaver and CSS. If you look at this page to ...


Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Coding Help > HTML Basics

Register Forum Rules FAQDonate Calendar Search Today's Posts Mark Forums Read

  #1 (permalink)  
Old 23-10-2008, 06:24 PM
Frontpage User
 
Join Date: Mar 2008
Location: Dublin
Posts: 27
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Eye4It will become famous soon enough
Cool Problem with centering a layout-relative to browser window size using CSS

Hi all
I'm having trouble centering a layout. I'm using Dreamweaver and CSS. If you look at this page to understand what I mean:
TheDigiPort - www.thedigiport.com : You have located the Digital World.
If you resize your browser window on that site, the site moves so as it remains in the center always, obviously until you go too far then a horizontal scroll bar appears.
I've searched everywhere for the answer to this question, and I'm betting it's a real simple and easy fix too!!
Can anyone help?
Cheers

edit: I'm using the "draw AP Div" method in Dreamweaver to place all the elements on the page.

Last edited by Eye4It; 23-10-2008 at 06:28 PM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 23-10-2008, 06:53 PM
n3tFl0w's Avatar
Wannabe Geek
 
Join Date: Jan 2008
Location: Work...
Posts: 445
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
n3tFl0w is a splendid one to beholdn3tFl0w is a splendid one to beholdn3tFl0w is a splendid one to beholdn3tFl0w is a splendid one to beholdn3tFl0w is a splendid one to beholdn3tFl0w is a splendid one to beholdn3tFl0w is a splendid one to behold
Default

Can you post your css?

Most of the time you wrap your page in a wrapper div and use something like the follwing css to centre it...

body {
text-align: center;
}

#container {
margin: 0 auto;
width: xxxpx;
text-align: left;
}


That'll work on nearly every browser.
__________________
My Blog thing!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 23-10-2008, 07:16 PM
Frontpage User
 
Join Date: Mar 2008
Location: Dublin
Posts: 27
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Eye4It will become famous soon enough
Question

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</title>
<style type="text/css">
<!--
body {
    background-image: url(bg.jpg);
    margin-left: 0%;
    margin-right: 0%;
}
#apDiv1 {
    position:absolute;
    left:277px;
    top:85px;
    width:214px;
    height:7px;
    z-index:1;
}
#apDiv2 {
    position:absolute;
    left:75px;
    top:73px;
    width:29px;
    height:710px;
    z-index:1;
    background-image: url(leftcol.jpg);
}
#apDiv3 {
    position:absolute;
    left:840px;
    top:73px;
    width:30px;
    height:710px;
    z-index:2;
    background-image: url(rightcol.jpg);
}
#apDiv4 {
    position:absolute;
    left:104px;
    top:66px;
    width:736px;
    height:16px;
    z-index:3;
    background-image: url(topcol.jpg);
}
#apDiv5 {
    position:absolute;
    left:297px;
    top:824px;
    width:193px;
    height:64px;
    z-index:4;
}
#apDiv6 {
    position:absolute;
    left:104px;
    top:772px;
    width:736px;
    height:19px;
    z-index:5;
    background-image: url(botbar.jpg);
}
#apDiv7 {
    position:absolute;
    left:104px;
    top:81px;
    width:736px;
    height:692px;
    z-index:6;
    background-color: #FFFFFF;
}
#apDiv8 {
    position:absolute;
    left:100px;
    top:83px;
    width:228px;
    height:46px;
    z-index:7;
}
#apDiv9 {
    position:absolute;
    left:79px;
    top:130px;
    width:484px;
    height:131px;
    z-index:8;
}
#apDiv10 {
    position:absolute;
    left:79px;
    top:293px;
    width:787px;
    height:35px;
    z-index:9;
    background-image: url(navbg.jpg);
}
#apDiv11 {
    position:absolute;
    left:79px;
    top:328px;
    width:235px;
    height:451px;
    z-index:10;
    background-image: url(leftbar.jpg);
}
#apDiv12 {
    position:absolute;
    left:79px;
    top:344px;
    width:235px;
    height:26px;
    z-index:11;
    background-image: url(navhebg.jpg);
}
-->
</style>

</head>
<body>
<div id="apDiv2"></div>
<div id="apDiv3"></div>
<div id="apDiv4"></div>
<div id="apDiv5"></div>
<div id="apDiv6"></div>
<div id="apDiv7"></div>
<div id="apDiv8"><img src="u.jpg" width="356" height="45" /></div>
<div id="apDiv9"><img src="image1.jpg" width="787" height="163" /></div>
<div id="apDiv10"></div>
<div id="apDiv11"></div>
<div id="apDiv12"></div>
<div align="left"></div>

</body>
</html>
I haven't made the style sheet external yet :P
So how do I assign a wrapper tag?
Thanks for the speedy response.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 23-10-2008, 07:47 PM
gav240z's Avatar
Wannabe Geek
 
Join Date: Dec 2007
Location: Rathmines, Dublin
Posts: 465
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
gav240z is just really nicegav240z is just really nicegav240z is just really nicegav240z is just really nicegav240z is just really nice
Default

Change body to the following:
<style type="text/css">
<!--
body {
margin: 0 auto;
}

However it won't work in IE6. So use what n3tFl0w above suggested. Use a wrapper div and use text-align:center on the body to accommodate IE6.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 23-10-2008, 09:54 PM
Frontpage User
 
Join Date: Mar 2008
Location: Dublin
Posts: 27
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Eye4It will become famous soon enough
Default

I have tried that, and it has worked to a certain extent for me. I'm having trouble placing div tags inside of the wrapper div. The first element (say, an image) I put in will center the way I want the whole page to do, but Dreamweaver won't let me move the image around, and anything else I place on the page stays where I put it, instead of moving with the image :S

EDIT: That site I gave as an example uses tables, and it's possible in Dreamweaver to use Layout Tables to achieve this. What are your thoughts on this? Is it up to standards to do it this way?

Last edited by Eye4It; 23-10-2008 at 10:09 PM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 23-10-2008, 10:40 PM
gav240z's Avatar
Wannabe Geek
 
Join Date: Dec 2007
Location: Rathmines, Dublin
Posts: 465
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
gav240z is just really nicegav240z is just really nicegav240z is just really nicegav240z is just really nicegav240z is just really nice
Default

Quote:
Originally Posted by Eye4It View Post
I have tried that, and it has worked to a certain extent for me. I'm having trouble placing div tags inside of the wrapper div. The first element (say, an image) I put in will center the way I want the whole page to do, but Dreamweaver won't let me move the image around, and anything else I place on the page stays where I put it, instead of moving with the image :S

EDIT: That site I gave as an example uses tables, and it's possible in Dreamweaver to use Layout Tables to achieve this. What are your thoughts on this? Is it up to standards to do it this way?
To move an image around use background-position: 50% 0;
that would set an image at the center of the screen.

You can also use short hand:
background:#360404 url(img/bg.png) no-repeat 50% 0pt

first part is color: #360404
second part is image url.
3rd part is how to tile the image.
4th part is position of image relative to containing div.

Dreamweaver is a good editor, but I wouldn't rely on it for understanding CSS.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 24-10-2008, 01:27 AM
ghost's Avatar
Wannabe Geek
 
Join Date: Dec 2007
Location: Ennis
Posts: 189
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
ghost will become famous soon enough
Default Centered page in all browsers

Another suggestion for you
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="XHTML namespace">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled</title>
<style type="text/css">
<!--
body       { margin:0 ; padding:0 ; background-image: url( 'bg.jpg' ); }
#container { margin:0 auto ; width:950px ;   }
#container { min-height:500px ; height:auto !important ; height:500px  }
#container { border:1px solid #cccccc; background-color:#ffffff ;  }
-->
</style>
</head>
<body>
<div id="container">
<h1>Container Style</h1>
<p>A 950 pixel wide container centered <br />With 500 pixel min height<br />Border and background color</p>
</div>
</body>
</html>
For the rest of your code position:absolute is probably not the best way to go
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
browser, centering, css, layoutrelative, problem, size, window

Thread Tools
Display Modes

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
Size of PM inbox paul Forum Feedback, Development and Competitions 24 13-09-2008 09:16 PM
Table layout vs CSS layout ... dbee Coding Help 21 12-07-2007 11:57 AM
CSS font size Gavin HTML Basics 10 22-04-2007 12:52 PM
Relative worth of position gothwalk Search Engine Optimisation 4 19-09-2006 02:48 PM


Sponsored links

Pepperjam Network
Paid On Results www.zanox.com


All times are GMT +1. The time now is 07:11 PM.


Powered by: vBulletin Version 3.8.2, Copyright ©2000 - 2009, Jelsoft Enterprises Limited.
Hosted in Ireland by Blacknight - Test your ISP |Irish Hosting Directory| Armchair.ie|Logo by Eden Web Design|Avatars by Afterglow |Latest Blog Entries | VPS HostingAd Management by RedTyger

Search Engine Friendly URLs by vBSEO 3.3.0

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 44 45 46 47 48 49 50 51