HighDots Forums  

absolute positioning

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)


Discuss absolute positioning in the Cascading Style Sheets forum.



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

Default absolute positioning - 04-11-2009 , 05:04 AM






Hello,

i have a <div id="main"> container that i want to be centered on the
browser-window.
so i gave it margin:0px auto;
everything fine.

now i want a second container positioned absolute in the <div id="main">,
not in the browser-window.
not possible, because <div id="main"> has no position:absolute;.

if i give <div id="main"> the position:absolute; , it is not longer centered
in the browser-window.
but it should be centered also if someone resizes the window.

Any workaround for that?

Thanks for any idea,
Martin Nadoll



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

Default Re: absolute positioning - 04-11-2009 , 05:47 AM






Martin Nadoll wrote:
Quote:
Hello,

i have a <div id="main"> container that i want to be centered on the
browser-window.
so i gave it margin:0px auto;
everything fine.

now i want a second container positioned absolute in the <div
id="main">, not in the browser-window.
not possible, because <div id="main"> has no position:absolute;.

if i give <div id="main"> the position:absolute; , it is not longer
centered in the browser-window.
but it should be centered also if someone resizes the window.

Any workaround for that?
#main {position: relative;}




Reply With Quote
  #3  
Old   
Ben C
 
Posts: n/a

Default Re: absolute positioning - 04-11-2009 , 11:14 AM



On 2009-04-11, Martin Nadoll <martin (AT) nadoll (DOT) de> wrote:
Quote:
Hello,

i have a <div id="main"> container that i want to be centered on the
browser-window.
so i gave it margin:0px auto;
everything fine.

now i want a second container positioned absolute in the <div id="main">,
not in the browser-window.
not possible, because <div id="main"> has no position:absolute;.

if i give <div id="main"> the position:absolute; , it is not longer centered
in the browser-window.
but it should be centered also if someone resizes the window.

Any workaround for that?
If you want to center an absolutely positioned div, you need to set left
and right both to 0 (and then left and right margins to auto, as you
have done).

e.g.

#main
{
left: 0;
right: 0;
margin: 0 auto;
}


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 - 2009, Jelsoft Enterprises Ltd.