Jump to content

How to Center Images in CSS


vajra_hendry

Recommended Posts

This may sounds overly simple.  However I have looked his up in my CSS book, and looked at severla websites.

 

My problem is that I want to center an image on my page (well center the image within its containing block).

 

I would normally just use Absolute or Relative positioning, however the Banner that im trying to align is  an images thats passed from PHP so its different everytime!!  COuld be like 125x125 pixles or it might be 468 x 60 pixels.  So whatever the image is , I need CSS to just align is Center!!

 

Any ideas please?!  ::)

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/67623-how-to-center-images-in-css/
Share on other sites

I would do the following:

 

/*css*/
.image_center {margin:0 auto;}

 

<!-- xhtml -->
<div class="image_center">
   <img src="" alt="" />
</div>

 

The margin value of "auto" will automatically create equal left/right margins around an element with class="image_center"...which centers it within the container element.

 

Make sure you're using a valid doctype and validate your CSS and markup.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.