Vertical Aligned Text and Image in list

不问归期 提交于 2019-12-23 02:45:29

问题


Is there a way of vertical aligning text and an image in a list?

e.g.

<li>Some text here <img src="image.jpg" alt="" /></li>

The text doesn't align in the middle of the side of the image, it appears at the bottom then the image is next to it. I need the text to be in the center point between the image on the side.

What's the best way of doing it? I know having a image inside a list isn't valid HTML (AFAIK).

Thanks :)


回答1:


You can use

li img {vertical-align: middle;}

if text fits one line




回答2:


If the text doesn't wrap, you can set line-height same as the height of image:

li { line-height: 42px }

And yes, having img inside li is perfectly valid, since img is (by default) inline element while li is block level element.



来源:https://stackoverflow.com/questions/2716490/vertical-aligned-text-and-image-in-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!