大家好,我想将一个 div(封面)覆盖在另一个 div(区域)上,我检查了与我类似的帖子,但没有一个能够满足我的特定需求。根据我的测试,它仅出现在主 div(区域)下方。容器 div(阅读器)的位置是固定的,这是我能够填充整个屏幕的唯一方法。请检查我下面的代码。谢谢
<style>
html,
body {
box-sizing: border-box;
min-height: 100%;
margin: 0;
padding: 0;
}
#reader {
position: fixed;
width:100%;
height: 100%;
top: 10;
left: 20;
bottom: 10;
right: 20;
background: wheat;
display: flex;
flex-direction: column;
}
#reader #toolbar {
flex: 0 1 auto;
display: flex;
justify-content: space-between;
background: rgba(0,0,0,0.05);
padding: 10px;
}
#reader #toolbar .left {
flex: 0 1 auto;
}
#reader #toolbar .center {
flex: 0 1 auto;
}
#reader #toolbar .right {
flex: 0 1 auto;
}
.area {
flex: 1 0 auto;
display: flex;
margin: 10px 15px;
padding: 10px;
}
#reader #area div {
position: absolute;
width: 90%;
top: 10px;
left: 5%;
bottom: 10px;
right: 5%;
}
.cover {
z-index: 9;
}
</style>
<div id="reader">
<input type="file" id="bookChooser">
<select id="toc"></select>
<div id="area" class="area"></div>
<div class="area cover"></div> <!-- This should cover the div area above, not pushed down -->
<button id="prev" type="button"><</button>
<button id="next" type="button">></button>
</div>
Run Code Online (Sandbox Code Playgroud)
小智 10
将两个 div 放入根 div 中。然后将根 divposition:relative和覆盖 div 设置为绝对。固定高度和宽度。并在覆盖 div 上应用 display:block。如果仍然不起作用,则应用 z-index。
这应该是这样的: HTML:
<div class="parent">
<div id="area" class="area"></div>
<div class="area cover"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.parent{
position: relative;
height:200px;
width: 200px;
}
.cover{
position: absolute;
height: 100%;
width: 100%;
display: block;
z-index: 999;
}
Run Code Online (Sandbox Code Playgroud)
希望这对你有用。