Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.