在锚元素中居中图像 [英] Centering an image within an anchor element

查看:140
本文介绍了在锚元素中居中图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个锚元素,看起来像这样

I have an anchor element that looks like this

<a href="url"><img scr="imgurl"/>Text</a> 

我想要锚点元素的图像和文本垂直对齐。我试过添加vertical-align(css),填充,边距,ets,但图像不会垂直对齐文本。应该很简单,我只是不能想出来。有任何想法吗?感谢

I'd like the image and the text of the anchor element to vertically align. I've tried adding vertical-align (css), padding, margins, ets, but the image will not vertically align with the text. Should be simple, I just can't figure it out. Any ideas? Thanks

推荐答案

垂直对齐仅真正适用于兄弟元素。这应该工作:

Vertical align only really applies to sibling elements. This should work:

<a href="url"><img scr="imgurl"/><span>Text</span></a>

使用CSS:

a img, a span { vertical-align: middle; }

这篇关于在锚元素中居中图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆