For some reason when I first started learning CSS and the box model, one of the hardest things I couldn’t figure out how to do was simply center a box in the middle of the screen. Back in the old table days, it was easy — just wrap center tags around your table, and viola.

Well now I know much better. With CSS its actually just as easy. Just add the following to lines to your CSS div definition of choice:

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

This probably only works on relatively positioned elements, that are in the normal flow.


No Responses to “Centered CSS, the easy way”  

  1. No Comments

Leave a Reply



 

Bad Behavior has blocked 20 access attempts in the last 7 days.