html - 在绝对定位的 div 元素后恢复正常的 HTML 流
问题描述
在绝对定位的 div 元素之后是否可以恢复正常的 HTML ?我正在尝试particle.js
在标题 div 中使用背景,其顶部是子元素(仅包含一些文本)。然后从父 div(particle-js div)的末尾,我想要正常的 HTML 流。
#parent {
position: absolute;
height: 200px;
width: 200px;
background-color: red;
}
#child {
position: relative;
left: 50px;
top: 50px;
height: 50px;
width: 50px;
background-color: green;
}
#after-parent {
background-color: blue;
}
<div id="parent">
<p>Parent div</p>
</div>
<div id="child">
<p>child div</p>
</div>
<div id="after-parent">
<h1>Normal HTML flow after parent div</h1>
</div>
解决方案
您可以将 #parent 和 child 包装在另一个相对 div 中,并为其指定高度 https://jsfiddle.net/f6phun8a/2/
#parent {
position: absolute;
height: 200px;
width: 200px;
background-color: red;
}
#outer {
position: relative;
height: 200px;
}
#child {
position: relative;
left: 50px;
top: 50px;
height: 50px;
width: 50px;
background-color: green;
}
#after-parent {
background-color: blue;
}
<div id="outer">
<div id="parent">
<p>Parent div</p>
</div>
<div id="child">
<p>child div</p>
</div>
</div>
<div id="after-parent">
<h1>Normal HTML flow after parent div</h1>
</div>
推荐阅读
- mysql - MySql GROUP_CONCAT() 将两行打印为单行
- javascript - 在 Zurb Foundation “显示”对话框中时,反应表单 onSubmit 和 onClick 不会触发
- google-cloud-functions - 从 Cloud Functions 触发 Google Cloud API
- reactjs - Framer Motion/React- 在将新变体传递给运动组件后,framer 的内联样式持续存在
- java - 我怎样才能让我的程序只输入特定的单词,如果输入的不是所说的单词,重试输入
- linux - 删除多行 CSV 记录中的换行符
- python - 重试时芹菜何时调用on_failure
- regex - C# Regex 关于模式的几个问题
- python - Queryset AttributeError:“dict”对象没有属性“_meta”
- javascript - HTML 和 Discord Python - Javascript 解析