Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Making CSS generic for image centering

Making CSS generic for image centering

Problem

Below is my CSS. It is used to centre an image. (This code works)

.imagecentre{
    width: 25px;
    position:relative;
    margin:0 auto;

}

In order for it to work, you need to state the width. However, not all my images are 25px.

How can I make this Css Generic enough to accommodate all images using javascript?

Problem courtesy of: Goaler444

Solution

If you only want to center an image in a container, you can set text-align: center on the container, regardless of what styles you have on the image:

Solution courtesy of: Dan Dascalescu

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

Making CSS generic for image centering

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×