Tip Details Add a Related Tip

Rate as: Positive Negative

Using CSS to center text

Most people are aware that you can center text in CSS using the text-align property like so:

p { text-align: center; }

The only down-side to this is that the centering occurs within the full width of the container element. For example, the paragraph element defined above will center the text across the entire page if this paragraph is in the main body of the page.

You could add divs, spans, and the like to constrain the size of the element in which it is centered, but it is also possible to do this purely in CSS. To do so, define the width of the element and set the margins to auto, like so:

p { margin-left: auto; margin-right: auto; width: 10em; }

Using this, you can get text that it centered in the page at whatever width you desire.
Rating: no ratings, 0 total Votes
Categories: CSS web
Added: on Apr 04, 2007 at 7:48 am
Added By: Marcos84

Comments on this Tip

Add a Comment
There are no comments for this tip
Your Comment:
(how to format)
Rate This Tip:

Verify Humanity:
Sorry, we know it's annoying, but please enter the characters shown in the image to the left so that we know you're an actual person and not an evil spammer. Thanks.
       

Related Tips

Always use the label attribute when creating radio buttons or checkboxes in forms

Categories: HTML CSS coding web
100% positive, 1 comment - last added on Mar 14, 2007 at 2:44 pm
– Tip added by Marcos84 on Mar 14, 2007 at 1:44 pm

getting rounded corners without using background images

100% positive, 0 comments
– Tip added by tipstr on Mar 13, 2007 at 10:35 am

CSS effect to create text gradients

Categories: css web design tutorial
100% positive, 0 comments
– Tip added by an anonymous user on Jan 27, 2008 at 6:31 pm

Wrap web text to any shape

100% positive, 0 comments
– Tip added by an anonymous user on Dec 16, 2007 at 10:35 am

Code for creating Javascript CSS charts

no ratings, 0 comments
– Tip added by an anonymous user on Aug 21, 2007 at 12:23 pm

Cool cutting-edge CSS demos

Categories: CSS coding web web 2.0
no ratings, 1 comment - last added on Mar 08, 2007 at 8:17 pm
– Tip added by Marcos84 on Mar 08, 2007 at 3:27 pm

compressing javascript

100% positive, 0 comments
– Tip added by an anonymous user on Jun 12, 2008 at 3:02 pm

Surfing the web anonymously

Categories: security web anonymous
100% positive, 0 comments
– Tip added by an anonymous user on Jun 12, 2008 at 8:03 am

How to Easily Install Joomla

100% positive, 0 comments
– Tip added by an anonymous user on May 29, 2008 at 4:07 pm

scheduling meetings

100% positive, 0 comments
– Tip added by an anonymous user on May 22, 2008 at 7:18 am

Avoid sounds in ads on web pages

100% positive, 0 comments
– Tip added by an anonymous user on Apr 21, 2008 at 12:21 pm

Telling when an iframe is done loading

100% positive, 0 comments
– Tip added by an anonymous user on Apr 18, 2008 at 8:05 am

Resize images

Categories: images web software
100% positive, 1 comment - last added on Apr 20, 2008 at 2:43 am
– Tip added by an anonymous user on Apr 06, 2008 at 9:03 am

Flip MySpace comments and pictures

100% positive, 0 comments
– Tip added by crtrlk on Apr 03, 2008 at 9:28 pm

xkcd comic extras

Categories: comics web fun easter eggs
100% positive, 1 comment - last added on Mar 28, 2008 at 2:14 pm
– Tip added by rlansky on Mar 28, 2008 at 1:56 pm

Avoid scams when selling on eBay or Craigslist

100% positive, 0 comments
– Tip added by listingsally on Mar 28, 2008 at 9:32 am

Run web apps on your Mac Desktop

Categories: Mac web web 2.0 desktop
no ratings, 0 comments
– Tip added by an anonymous user on May 23, 2008 at 4:07 pm

Building a search engine with Appengine and Yahoo

Categories: Python web search google
no ratings, 0 comments
– Tip added by an anonymous user on Apr 17, 2008 at 8:25 am

Make your photos look old with no software

no ratings, 0 comments
– Tip added by an anonymous user on Apr 16, 2008 at 4:00 pm

A creating a poll website with Django and appengine

Categories: technology python web
no ratings, 0 comments
– Tip added by an anonymous user on Apr 11, 2008 at 8:35 am