为什么内联块元素未对齐? [英] Why are inline block elements misaligned?

查看:115
本文介绍了为什么内联块元素未对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在带有vertical-align: top;div里面,我有两个元素,一个img和一个span(里面有aaa).

Inside a div with vertical-align: top; I have two elements, an img and a span (with aaa inside).

两个元素都设置了display: inline-block;widthheight.

Both elements have display: inline-block; and width and height set.

无论我做什么和尝试什么,这些元素都会被错误,如下图所示. 有什么问题,我该如何解决?

No matter what I do and what I try, the elements are MISALIGNED as shown on picture below. What is wrong and how can I fix this?

此问题发生在每个浏览器中-FF,IE,Safari ... http://jsfiddle.net/CaU59/

This problem occurs in every browser - FF, IE, Safari ... http://jsfiddle.net/CaU59/

推荐答案

您需要将vertical-align添加到元素本身,而不是它们的容器.正如您从与图像对齐的文本中看到的那样,它们当前已对齐baseline.

You need to add vertical-align to the elements themselves, not their container. They are currently aligned baseline as you can see from the text lining up with the image.

http://jsfiddle.net/CaU59/2/

这篇关于为什么内联块元素未对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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