简体   繁体   中英

How to vertical align text with center of image in HTML?

So I have an image "blah.jpg" and a name "Name" in HTML.

    <img src="blah.jpg"> Name

I want to make it so that the Name is center aligned with the center of the blah.jpg image instead of the text "Name" having a baseline at the bottom of the image.

What is the best way to accomplish this with no tables using CSS3 if possible?

In the page:

<img src="blah.jpg" class="centered"> Name

In css file:

img.centered {vertical-align:middle;}

No need for display: inline-block (which is not supported in some old browsers)

您可以在img元素上使用vertical-align:middle: http : //jsfiddle.net/Z35pw/

如果您想要单行而不定义额外的对象或属性,只需在<img .../>标记内添加style="vertical-align:middle"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM