html - 图像下方的空白
问题描述
我在我的 css 项目中遇到了一些问题。我试图将图像放在 div 中,并以某种方式在图像下方放置了一个空白。
这是我的html代码:
* {
box-sizing: border-box;
}
body {
margin: 0;
}
#top {
border: solid;
}
#page-top {
border: solid;
width: 1028px;
background: yellow;
margin: 0 auto;
}
#page-top img {
width: 30%;
border: solid;
display: inline-block;
}
<div id="top">
<div id="page-top">
<img src="https://i.imgur.com/7nqdfTK.png">
</div>
</div>
解决方案
内联元素的默认垂直对齐方式是基线,它为下行文本元素保留空间。通过将垂直对齐属性设置为顶部或中间来解决此问题。
* {
box-sizing: border-box;
}
body {
margin: 0;
}
#top {
border: solid;
}
#page-top {
border: solid;
width: 1028px;
background: yellow;
margin: 0 auto;
}
#page-top img {
width: 30%;
border: solid;
display: inline-block;
vertical-align: middle;
}
<div id="top">
<div id="page-top">
<img src="https://i.imgur.com/7nqdfTK.png">
</div>
</div>
推荐阅读
- wordpress - 本地 Wordpress 网站 (https) 未从本地网络外部加载
- python - 如何使用输出参数调用 C 函数
- html - 如何扩展按钮的悬停区域以便仍触发下拉?
- wordpress - Wordpress 页面不会从 Google 引荐来源加载,如果我直接浏览到它,加载正常
- javascript - 自动删除特定文件夹中的文件
- three.js - 着色器,不绘制视野内的物体
- javascript - 如何在 Javascript 中替换字符串中的特定单词组合?
- reactjs - 如何更新从处于状态的空数组中提取的输入值?
- node.js - app.post 不工作,使用 console.log 不打印任何内容。感谢你的帮助。(学习速递节点JS)
- diameter-protocol - 海鸥流量生成器。AVP 长度