html - 为什么和之间有既不是边距也不是填充的空间
元素?
问题描述
为什么元素之间有既不是边距也不是填充的空间<img>
?似乎两个元素<p>
之间不存在这样的空间<p>
*, *:after, *:before {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
text-decoration: none;
list-style-type: none;
}
html {
font-size: 16px;
}
body {
background-color: #f2f2f2;
font-family: "Helvetica", sans-serif;
height: 100%;
width: 100%;
line-height: 1.8rem;
color: #333333;
}
.summoner-icon {
max-width: 50px;
border-radius: 50%;
}
.match {
margin-bottom: 10px;
padding: 10px;
}
<div class='matches'>
<div>
<div class='match'>
<img class='summoner-icon' src="https://images.pexels.com/photos/433155/pexels-photo-433155.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=150" alt="">
<p>Test1</p>
<p>Test2</p>
</div>
</div>
</div>
解决方案
1)
你的问题是line-height
。删除(或减少)您的行高,它可以按您的意愿工作。
2)
图像默认显示inline
。修复此问题以将图像显示为block
关卡元素。
*, *:after, *:before {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
text-decoration: none;
list-style-type: none;
}
html {
font-size: 16px;
}
body {
background-color: #f2f2f2;
font-family: "Helvetica", sans-serif;
height: 100%;
width: 100%;
/*line-height: 1.8rem;*/
color: #333333;
}
.summoner-icon {
max-width: 50px;
border-radius: 50%;
display: block;
}
.match {
margin-bottom: 10px;
padding: 10px;
}
<div class='matches'>
<div>
<div class='match'>
<img class='summoner-icon' src="https://images.pexels.com/photos/433155/pexels-photo-433155.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=150" alt="">
<p>Test1</p>
<p>Test2</p>
</div>
</div>
</div>
推荐阅读
- python - 如何让用户为嵌入命令选择十六进制颜色?| 不和谐.py
- arrays - 使用 putchar 函数打印出数组时出现问题。获得大量符号作为输出
- python - 在 Google App Engine 上同步和异步 Python FastAPI 脚本
- php - 致命错误:未捕获的 ArgumentCountError:mysqli_select_db() 需要 2 个参数,1 个给定
- sql - 如何在 SQLite 中自动将自动增量 id 从一个表插入到另一个表?
- asp.net-core - MS Graph:从 .net core 2.0 中的 Adal 升级到 3.1 中的 Msal
- java - 为什么我的方法打印 null 而不是数组?
- reactjs - 当antd表中的列值发生变化时,如何立即更新汇总值?
- python - 在睡眠状态下运行 pynmea2 时,时间戳无法正确更新
- arrays - MongoDB中的查询不返回结果