Jump to content

DIV alignment


chiprivers

Recommended Posts

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.
Link to comment
https://forums.phpfreaks.com/topic/27013-div-alignment/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/27013-div-alignment/#findComment-123542
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.