Center an Image with CSS
- Posted On: March 30th, 2008
- Filed Under: CSS
Centering an image is a bit of a tricky endeavor. It used to be just a case of wrapping the image in <center> tags but that's no longer the case. In today's web standards we can't use the <center> code and as a result we need to develop some CSS code.
The following code is something I've been using for awhile now and I'm quite happy with it. It can be used to center images and can also work with text and certain types of media (like YouTube videos.)
To get started you'll want to open your stylesheet.css file and browse to the area which holds rules concerning images. This code doesn't have to go anywhere specifically - it's just helpful to put it near all the other image related rules.
In this post we're just going to create a CSS class that's meant to handle images that appear in posts - if you're so inclined you can also use it in your general theme structure too.
When you're first getting started with a WordPress theme there really are only six files that you need. With only these six files you can create a blog that has a consistent header and footer, has a dynamic (widgetized) sidebar, displays an index page, displays single pages/posts and even displays categories, archives and searches.