我有这样的html:
<div>
<span style="display: inline-block;height:20px">20</span>
<span style="display: inline-block;"><img src="img/ex.png"/></span>
</div>
我在第二个跨度中导入的图像是 15x15 像素
我可以用chrome检查,我可以看到第一个img的高度为15 第二个跨度的高度为 21。(第一个跨度的高度为 20,符合预期)
有人可以告诉我为什么第二个跨度的高度是 21 而不是 15 ???
谢谢,这让我发疯
我添加以下颂歌:
<!DOCTYPE html>
<html>
<head>
<style>
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
</style>
</head>
<body>
<div>
<span style="display: inline-block;height:20px">20</span>
<span style="display: inline-block;"><img src="img/ex.png"/></span>
</div>
</body>
</html>
最佳答案
要么图像比您想象的要大,要么图像具有您未考虑的填充/边距,要么跨度具有您未考虑的填充/边距。
- 检查 Chrome 中的每个元素,首先是图像,然后是跨度。
- 展开窗口右侧的指标
- 小图将向您显示元素大小的每个影响因素(内边距、边距、边框、元素大小)
关于javascript - 如何调试 div/span 的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7616233/