html - 标题 1 导致 DIV 分开
问题描述
我的页面有问题,它在 H1 和主页 DIV 部分之间出现间隙。2小时后,我似乎无法修复它。谁能告诉它哪里出错了。我希望顶部横幅和#mainarea 相互重叠。目前两者之间有一个小的差距。
body {
font-size: 15px;
font-family: 'Open Sans', sans-serif;
background-color: #f6f6f6;
padding: 0;
margin: 0;
border: 0;
}
#logo {
width: 100%;
height: 50px;
background-color: #000;
}
#mainarea {
width: 60%;
height: auto;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
background-color: #E70A0E;
height: 250px;
}
h1 {
font-size: 1.5em;
font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
font-weight: bolder;
font-style: normal;
padding-left: 15px;
}
<div id="logo">
</div>
<div style="clear: both;"></div>
<div id="mainarea">
<h1>This is a test </h1>
</div>
解决方案
设置overflow:auto;
并#mainarea
添加margin:auto
到h1
标签。
看,当您将 div 放入 div 时会发生什么:https ://stackoverflow.com/a/8529773/9947640
body {
font-size: 15px;
font-family: 'Open Sans', sans-serif;
background-color: #f6f6f6;
padding: 0;
margin: 0;
border: 0;
}
#logo {
width: 100%;
height: 50px;
background-color: #000;
}
#mainarea {
width: 60%;
height: auto;
margin-top: 0px;
margin-right: auto;
margin-left: auto;
background-color: #E70A0E;
height: 250px;
overflow:auto;
}
h1 {
font-size: 1.5em;
font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
font-weight: bolder;
font-style: normal;
padding-left: 15px;
margin:auto;
}
<div id="logo">
</div>
<div style="clear: both;"></div>
<div id="mainarea">
<h1>This is a test </h1>
</div>
推荐阅读
- vba - 如何等到从 UFT 的网页中删除/删除对象?
- pandas - 计算出的 pandas 列的最大值和 0
- npm - Vue CLI 3 - 将 TailwindCss 1.9 升级到 TailwindCss 2.0 时出错
- django - Django auto_now 计数结果在某个日期
- ajax - 如何处理 ASP.NET Core MVC 中的 AJAX 异常并显示自定义错误页面?
- reporting-services - SSRS:来自 web 服务错误的空字符串,即使使用 iif 语句
- java - 使用 JDB 检查 JVM 帧的操作数堆栈和局部变量数组
- javascript - GET 结果在 IE11 中为 undefined/null,直到对 webpack 文件进行了更改。任何想法为什么?
- java - catchException 不适用于@Transactional
- java - 春天的关系破裂