help with relative css positioning

liunx

Guest
hi,
I can layout my web site using css positioning where I specify the actually coordinates of where I want to put the image, i.e. absolute positioning,

now I want to be able to centre stuff on the page depending on how the user resizes their screen. How can this be done so thats it behaves like tables do when they have the 'centre' attribute. I tried using css positioning with precentages instead of pixels but everything goes out of sync when the screen is resized.
So how can this be done?
thanks a lotmargin:auto (as long as you don't set a left/right property)I just answered a similar question a few minutes ago :p but you'll need something like below.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Center whole layout</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen">
<!--
/* text-align: center; will center the layout for IE5-Win and IE6-Win
running quirks mode (no DOCTYPE tag at beginning of document). */
body {
margin: 0;
padding: 0;
text-align: center;
}

/* The auto left and right margins center the layout in standards
browsers, IE6-Win (in standards mode) and IE5-Mac. */
#wrapper {
margin: 0 auto 0 auto;
position: relative; /* Allows you to absolutely position elements based on this element's position */
text-align: left; /* Reset text alignment for Western languages. */
width: 770px;
}

/* Standards browsers will cut off portions of the left and right edges
of a layout if the browser viewport is too narrow, unless the
#wrapper <div> has a left and right border. Internet Explorer is not
affected by this, and the style rules are hidden. Setting the border
color to transparent initially returns a CSS syntax error at the W3C
CSS validator, so for the sake of validation, the border color is
set to transparent on a separate line. */
html>body #wrapper {
border: 1px solid #fff;
border-color: transparent;
border-top: 0;
border-bottom: 0;
}
-->
</style>
</head>
<body>
<div id="wrapper">
<!-- Place all HTML for the entire page here. -->
</div>
</body>
</html>
 
Back
Top