图像和文本垂直对齐?
我有一个如下所示的锚标记设置,
<a href='' title='' class='video-author-box hoverbox'>
<img style='height:32px;' src='IMAGE_URL' alt='' />
Username
</a>
问题是文本与图像顶部对齐,但我希望文本在锚和图像的中间对齐。
I have an anchor tag setup like below
<a href='' title='' class='video-author-box hoverbox'>
<img style='height:32px;' src='IMAGE_URL' alt='' />
Username
</a>
The trouble is that the text aligns to top of image, but I want the text to align in middle of the anchor and image.
Example: http://jsfiddle.net/qZFFX/2/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有两个简单的解决方案:
float: left
,这样它将变成内联,并添加vertical-align: middle
Fiddle 1
line-height
它的容器。小提琴 2
Here are two simple solutions for that:
float: left
of the image, so it will become inline, and addvertical-align: middle
Fiddle 1
line-height
of it's container to it.Fiddle 2
您可以
在用户名和样式周围添加
span
,如下所示示例: http:// /jsfiddle.net/qZFFX/3/
然后您可以根据需要调整
填充
。或者,您可以不使用
span
示例 2:http:// jsfiddle.net/qZFFX/5/
You could do this
Add a
span
around the username and style like soExample: http://jsfiddle.net/qZFFX/3/
Then you can adjust the
padding
as you see fit.Alternately, you could do this, without the use of
span
Example 2: http://jsfiddle.net/qZFFX/5/