如何将跨度与向右浮动的图像垂直对齐?
我正在尝试做一些与图像问题旁边的对齐文本非常相似的事情: 垂直对齐图像旁边的文本?
区别在于,我希望图像向右浮动,但当我使其浮动时似乎 float:right ;
,解决该问题的vertical-align
不再起作用了?有没有办法让 img 向右浮动并使文本仍然居中对齐?
<div style="width:100px">
<span style="vertical-align:middle">Doesn't work.</span>
<img style="vertical-align:middle;width:30px;height:30px;float:right">
</div>
提前致谢!
I'm trying to do something very similar to the aligning text next to an image question: Vertically align text next to an image?
The difference is, I want the image to float to the right, but it seems when I make it float:right;
, the vertical-align
that solved that problem doesn't work anymore? Is there a way to have the img float to the right AND have the text still middle aligned to it?
<div style="width:100px">
<span style="vertical-align:middle">Doesn't work.</span>
<img style="vertical-align:middle;width:30px;height:30px;float:right">
</div>
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使行高与图像相同。
Make the line-height the same as the image.
从图像中删除
float: right
。对于 div,放置text-align: right
。它应该可以解决问题。希望这有帮助。 :)
Remove the
float: right
from the image. For the div, placetext-align: right
. It should solve the problem.Hope this helps. :)