chiprivers Posted November 12, 2006 Share Posted November 12, 2006 I am new to the CSS positioning approach to page layout and have always used tables but I would like to try and use CSS in my current project.I think I get the gerneral box concept and how to position them relativeley and absolutely but I can not work out how to centre a div on a page.What I am trying to do is have one <DIV> that dols the whole page, with a set width equal to the page width. I want this div to be centred in the middlef the display are so that if the browser window is larger than the div, there will be equal blank space either side. How do I do this? If I were using a table to do this I would just include align="center" in the <table> tag but this does not seem to work in the <DIV> tag. Quote Link to comment https://forums.phpfreaks.com/topic/27013-div-alignment/ Share on other sites More sharing options...
wildteen88 Posted November 12, 2006 Share Posted November 12, 2006 You'll want to use auto margins.Before using auto margins make sure you have a valid Doctype (XHTML Transitional DTD should be fine) and your div you wish to centre has a width set.To center the div add this to your CSS for the div you wish to center:[code]margin: 0 auto;[/code]Also when positioning your divs dont use absolute/relative positioning instead use floats. Quote Link to comment https://forums.phpfreaks.com/topic/27013-div-alignment/#findComment-123542 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.