Forum Moderators: open

Message Too Old, No Replies

Layers

Relative Positioning.

         

fashezee

2:42 pm on Apr 30, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am using a layer defined by the DIV tag, that I would like to align in the center of the page at all times. Regardless of the width of the page, the layer should always remain in the center.

Any suggestions would be much appreciated.
GO HABS GO !!!

tedster

2:48 pm on Apr 30, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's a pretty thorough page on this topic at:
[dhtmlnirvana.com...]

papabaer

3:35 pm on Apr 30, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"Centered" is a relative condition... no pun intended. Sometimes only horizontal centering is required, other times vertical is needed as well.

The solution also depends on the above and if you require the div to maintain specific dimensions while retaining a centered position (example - width:400px) or if the div needs to be fluid in a simple horizontal placement.

If it is the former then Tedster's supplied resource might be the best solution; if you require a horizontal-centered liquid div, then margin settings will accomplish this:

.centered-div {
margin-right:5%;
margin-left:5%;
}

Of course you can adjust the percentages as suited to your use.

mivox

5:20 pm on Apr 30, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I created a centered div by nesting it inside a 100% div with margins:

#content { margin-right: 15%; margin-left: 15% }
#textblock { font-size: 16px; line-height: 20px; font-family: "Courier New", Courier, Monaco }

<div id="content">
<div id="textblock"></div>
</div>

Very similar to papabaer's suggestion, only it allows the textblock div to have its own separate background color/pattern, etc., to create the look of a 70% width "box" floating in the center of the screen.