HighDots Forums  

CSS Div Centering

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss CSS Div Centering in the Macromedia Dreamweaver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
JasonTheAdobeFan
 
Posts: n/a

Default CSS Div Centering - 07-05-2008 , 03:32 PM






Hi, I'm learning more into CSS and want to use divs to align and contain
everything on my site. Everything seems to work except being able to center the
whole page.

I have the folowing divs:
Container (this is what sets width and should center in the page)
the following should be inside the content div
Header (the header)
TopNavBar (horizontal nav bar)
Content (the content goes in here)
Footer (the footer)
[hr]
But I don't know how to float the container div to the center of the page. Any
help please?


Reply With Quote
  #2  
Old   
JasonTheAdobeFan
 
Posts: n/a

Default Re: CSS Div Centering - 07-05-2008 , 03:42 PM






Quote:
the following should be inside the content div
Oops, I meant the container div not the content div


Reply With Quote
  #3  
Old   
Murray *ACE*
 
Posts: n/a

Default Re: CSS Div Centering - 07-05-2008 , 03:51 PM



Are any of your divs absolutely positioned? You'll be sorry if they are! 8)

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================

"JasonTheAdobeFan" <webforumsuser (AT) macromedia (DOT) com> wrote

Quote:
the following should be inside the content div

Oops, I meant the container div not the content div


Reply With Quote
  #4  
Old   
Jeff
 
Posts: n/a

Default Re: CSS Div Centering - 07-05-2008 , 03:51 PM



set the width property to an exact demension or a %, and set the left &
right margins to "auto"

Jeff

"JasonTheAdobeFan" <webforumsuser (AT) macromedia (DOT) com> wrote

Quote:
the following should be inside the content div

Oops, I meant the container div not the content div



Reply With Quote
  #5  
Old   
JasonTheAdobeFan
 
Posts: n/a

Default Re: CSS Div Centering - 07-05-2008 , 04:18 PM



Quote:
Are any of your divs absolutely positioned? You'll be sorry if they are! 8)
Yes, the container div was. I changed it but now the "top: 0px;" doesn't work.
There is now a gap before the top.

Quote:
set the width property to an exact demension or a %, and set the left &
right margins to "auto"
Ok. Thanks I got it to center now. How about a tip to eliminate the gap at the
top? I tried changing the top margin to 0 and that didn't move it.



Reply With Quote
  #6  
Old   
Murray *ACE*
 
Posts: n/a

Default Re: CSS Div Centering - 07-05-2008 , 04:24 PM



Quote:
Yes, the container div was. I changed it but now the "top: 0px;" doesn't
work.
There is now a gap before the top.
Certainly, as those values are only applicable to absoutely or relatively
positioned elements.

Without being positioned, that static container div is now affected by the
default margins on the body tag. Manage those and the gap will likely
vanish, but it may not. If that's the case, then we'd need to see your code
to know else might be causing the gap.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================

"JasonTheAdobeFan" <webforumsuser (AT) macromedia (DOT) com> wrote

Quote:
Are any of your divs absolutely positioned? You'll be sorry if they are!
8)

Yes, the container div was. I changed it but now the "top: 0px;" doesn't
work.
There is now a gap before the top.

set the width property to an exact demension or a %, and set the left &
right margins to "auto"

Ok. Thanks I got it to center now. How about a tip to eliminate the gap at
the
top? I tried changing the top margin to 0 and that didn't move it.



Reply With Quote
  #7  
Old   
JasonTheAdobeFan
 
Posts: n/a

Default Re: CSS Div Centering - 07-05-2008 , 05:42 PM



Ok. Changing the margin-top for the body in the external style sheet fixed the
gap. So in looking through www.w3schools.com I learn what a lot of the elements
and attributes are but it doesn't go into as much detail as you did about why
there would be a difference between absolute and relative, versus not having a
position set.

Thanks.


Reply With Quote
  #8  
Old   
Murray *ACE*
 
Posts: n/a

Default Re: CSS Div Centering - 07-05-2008 , 05:59 PM



This may help you understand positioning a bit -

There are 4 different types of positioning:
Absolute
Relative
Fixed
Static

Here is a brief explanation of each kind of positioning (with regard to
placement of elements on the page only)....

Position:absolute (or A/P elements)
-----------------------
This does several things -
1. It 'removes' the element from the flow of the code on the* page so that
it can no longer influence the size or position of any other pa*ge element
(except for those contained within it, of course).

2. The absolutely positioned element takes its position from the position of
its closest PA*RENT *positioned* element - in the absence of any explicitly
positioned parent, this will default to the <body> tag, which is always
positioned
*at 0,0 in the browser viewport.

This means that it doesn't matter where in the HTML code the laye*r's code
appears (between <body> and </body>), its location on the screen will not
change (this assumes that you have not positioned the A/P element within
a table or another A/P element, of course). Furthe*rmore, the space in
which
this element would have appeared were it not positi*oned is not preserved
on the screen. In other words, absolutely positioned elements don't take
up any space on the page. In fact, they FLOAT over the page.

Position:relative (or R/P elements)
----------------------
In contrast to absolute positioning, a relatively positioned page element is
*not* removed from t*he flow of the code on the page, so it will use the
spot
where it would have* appeared based on its position in the code as its
zero point reference. If* you then supply top, right, bottom, or left
positions
to the style for this *element, those values will be used as offsets from
its
zero point.

This means that it DOES matter where in the code the relativ*ely positioned
element appears (, as it will be positioned in that location (*factoring in
the offsets) on the screen (this is true for any placement in the code).
Furthermore, the space where this e*lement would have appeared is
preserved in the display, and can therefore* affect the placement of
succeeding elements. This means that the taller a relatively
positioned element is, the more space it forces on the page.

Position:static
-------------------
As with relative position, static positions also "go with *the flow". An
element with a static position cannot have values for offset*s (top, right,
left, bottom) or if it has them, they will be ignored. Unless explicitly
positioned, all div elements default to static positioning.

Position:fixed
------------------
A page element with this style will not scroll as the page c*ontent scrolls.
Support for this in elements other than page backgrounds is *quirky

There are several other things you need to know:

1. ANY page element can be positioned - paragraphs, tables, images, lists,
etc.
2. The <div> tag is a BLOCK level tag. This means that if it is not
positioned or explicitly styled otherwise, a) it will always begin on a new
line on the screen, and b) it will always force content to a new line below
it, and c) it will always take up the entire width of its container (i.e.,
width:100%).
3. The placement of A/P elements *can* affect the BEHAVIOR of other
elements
on the page. For example, a 'layer' placed over a hyperlink will mask that
hyperlink.

You can see a good example of the essential difference between absolute and
relative positioning here -

http://www.great-web-sights.com/g_layersdemo.asp

You can see a good demonstration of why using layers for a page layout tool
is dangerous here -

http://www.great-web-sights.com/g_layer-overlap.asp


--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================

"JasonTheAdobeFan" <webforumsuser (AT) macromedia (DOT) com> wrote

Quote:
Ok. Changing the margin-top for the body in the external style sheet fixed
the
gap. So in looking through www.w3schools.com I learn what a lot of the
elements
and attributes are but it doesn't go into as much detail as you did about
why
there would be a difference between absolute and relative, versus not
having a
position set.

Thanks.



Reply With Quote
Reply




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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.