Use CSS to solve the problem of vertical centering of image IMG
Author:Eve Cole
Update Time:2009-06-12 17:52:58
As we all know, if you want to align images and text vertically in the center, you can add the align=absmiddle attribute under the IMG tag. However, the align=absmiddle attribute fails the W3C verification. So can I use CSS to replace IMG? The align=absmiddle attribute can be used to achieve vertical centering. The answer is yes. You can add vertical-align:middle; to CSS to achieve this:
<div><img style="vertical-align:middle;" src="/uploadfile/png/IconBuffet/Redmond/close_32.png" />Use CSS to achieve vertical center alignment of images and text</div><br /> <br />
<div><img src="/uploadfile/png/IconBuffet/Redmond/close_32.png" />This is the effect without adding styles</div><br /><br />
<div><img align=absmiddle src="/uploadfile/png/IconBuffet/Redmond/close_32.png" />This is to use align=absmiddle to achieve vertical center alignment of pictures and text</div>
From the effect point of view, it seems that the implementation using CSS is slightly better, but it feels much better to control it with CSS.