Properly centering items with CSS

In the old days, things were so easy – one could just use <center>put stuff here</center> and be done with it. But as you know, this had it’s limitations – and not, it’s not part of the XHTML standard. Instead, you’re supposed to use CSS. But how do you make things centered? Well, there are really two ways – depending on what you are trying to do:
Centering text:
This is easy. You can just create a CSS class (or apply a style) of "text-align: center;" done!
Centering a div, block or container:
This, isn’t as obvious. text-align doesn’t work – and you want to stay away from using <center />. Even if you could use center ALL of the elemtents that are withint that container/div-tag or span-tag are going to be centred too, which is probably not what you want. So, here’s what I use and it seems to work. Plus this should work with with everything from a div tag to centering the main table that holds the contents for your whole site:






Posted in ASP.NET, Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Enter your email address to follow this blog and receive notifications of new posts by email.

Join 9 other followers

%d bloggers like this: