Jump to content

Recommended Posts

Put them in a super container and apply the following to said container:

 

margin-left: auto;
margin-right: auto;

 

Don't forget to use float: left on the elements you want to place side by side, and give them distinct widths (whether by percentage or invariable pixels).

This might get complicated. Depending on if both boxes are fixed widths or not, a "super" parent container may or may not worked.

 

You need a fixed width to center using margion: 0 auto;

 

If you don't have a fixed width, you could utilize some awesome css2! Display: table; Doesn't work in IE7, but IE8 finally supports it.

You need a fixed width to center using margion: 0 auto;

 

Actually, you just need a declared width that is smaller than its parent container - it could be pixel (fixed) or percentage (fluid).

 

The whole point of "margin: 0 auto" is top and bottom are "0" and right and left are "auto". It is the "auto"  that determines how far each side's margin should be based on the container's declared width in relation to its parent container's width. If no width is declared, then 100% is assumed. There are no margins of a box that is 100% the width of its parent (there is nothing to auto calculate to).

 

 

 

 

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.