Center aligning image inside <DIV> tag

Say, you want to center align an image, inside a <DIV>. Looks like a small thing,doesn’t it ? I recently faced this problem, so I googled for a solution. This turns out to be a classic problem of web page designing. The most convenient way I discovered to solve this was to use TABLE inside the DIV.

<td style=”width:25px;height:25px” valign=”middle” align=”center”>
<img src=”myimage” />

It looks like center alignment is only supported for TDs in most browsers. I found a couple of solutions on the Internet, but I thought they were too lengthy and complicated for simple task like mine.

Copyright (c) 2007-2014 Ashish Patil . Please read FAQ for more details.

comments powered by Disqus