Hi everyone
The following code contains a "body" ancestor element and two child elements: "Startpage" and "main".
I wanted to place "Start Page" which is a brown image excactly at the middle of "body" so i made it an "Absolute"
position with "margin:auto", assuming "auto" centers an element.
I wanted "main" to be horizontally centered on "Body" and on top of "Startpage" so I made it an "Absolute" position with
margin top: 40 px and left/right: "Auto".
Attched is the code and a screenshot.
Would anyone please tell me why the brown "startpage" element and the "main" as well are not centered ?!
What do I have to do to center it?
Thanks a lot !
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>to_sitepoint</title> <style type="text/css"> html, body, div, ul { margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline; } body { background-image:url('background.gif'); background-repeat:no-repeat; background-attachment:fixed; background-position:center; text-align:center; position:relative; } #startpage { position:absolute; margin:auto; width:960px; height:498px; background-image:url('startpage.png'); background-repeat:no-repeat; background-position:center; } #main { position:absolute; width:950px; height:30px; margin:40px auto 0; border:2px solid #8c8b4b; } #main li { width:92px; height:30px; float:left; list-style-type:none; border:2px solid red; } li.menu1 { background-image:url('images/men1.png'); } li.menu2 { background-image:url('images/men1.png'); } } </style> </head> <body> <div id="startpage"></div> <ul id="main"> <li><a href="#">menu item1</a></li> <li>menu item2>menu item1</li> </ul> </body> </html>



Reply With Quote

. Basically move it over 50% and drag it back over left to center.

Bookmarks