html - 包装器 div 旁边的 div 之前的额外空间
问题描述
在 id="test" 的 div 之前接收空行。不想要测试 div 之前的空间。带有 Parent & child 的 Wrapper div 与其相邻。尝试了很多 css 但无法删除空间。
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Coe</title>
<link rel="stylesheet" href="styles.css">
<style>
.footer-mgblock {
border:1px solid red;
margin:0px;
padding:0px;
}
.footer-mgblock .mainSection {
background: #000000;
border:1px solid green;
color: #FFFFFF;
padding:0px;
margin: 0px;
}
</style>
</head>
<body>
<p> Hello </p>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans+Condensed:wght@300;700&display=swap" rel="stylesheet">
<div class="footer-mgblock">
<div class="mainSection">
child
</div>
</div>
<div id="test" style="border:1px solid red;margin:0px;padding:0px">
testdiv
</div>
</body>
解决方案
在 #test 之前有一个不起眼的符号<div>
。您需要将其删除,间隙将消失。
复制并粘贴下面的代码(注意:该符号不会以 SO 代码格式显示,但如果将代码复制到 CodePen 中,您可以看到它 - https://codepen.io/fraggley/pen/VwvNJZe - 查看</div>
#test div 之前的标记):
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Coe</title>
<link rel="stylesheet" href="styles.css">
<style>
.footer-mgblock {
border:1px solid red;
margin:0px;
padding:0px;
}
.footer-mgblock .mainSection {
background: #000000;
border:1px solid green;
color: #FFFFFF;
padding:0px;
margin: 0px;
}
</style>
</head>
<body>
<p> Hello </p>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans+Condensed:wght@300;700&display=swap" rel="stylesheet">
<div class="footer-mgblock">
<div class="mainSection">
child
</div>
</div>
<div id="test" style="border:1px solid red;margin:0px;padding:0px">
testdiv
</div>
</body>
推荐阅读
- r - R如何合并2个列表
- javascript - 当输入框字符串长于框大小时,Vue Sortable + Draggable 不起作用
- python - 如何将 url 作为 slug 字段发送到 Django 中的 url
- python - 为什么我们需要将测试函数包装在一个类中?
- ruby-on-rails - Rails `create` 验证要求
- sql - 如何在服务器上连接我的网站和数据库
- javascript - 如何在现有网站中实现 Node.js 聊天应用程序?
- hunspell - hunspell 标记缺少字符且未正确排序
- node.js - 节点 MongoDB collection.findOne() 返回 null
- javascript - 如何将 emojioneArea(独立)选择值添加到文本字段?jQuery Rails 6.0.0