【发布时间】:2018-11-01 12:13:58
【问题描述】:
我有两个 flexbox 大小的 div 的设置,在其中一个我有一个设置为固定位置的标题。我将如何使它的宽度为父级的 100%?无论宽度如何,它都需要留在父级内部。谢谢。
.block1 {
height: 102.5%;
margin: 0px;
padding: 0px;
flex-basis: 35%;
flex-grow: 1;
flex-shrink: 1;
position: relative;
overflow: scroll;
background-color: white;
outline: solid red 1px;
}
.block2 {
outline: solid red 1px;
height: 102.5%;
margin: 0px;
padding: 0px;
flex-basis: 65%;
flex-grow: 1;
flex-shrink: 1;
position: relative;
overflow: scroll;
background-color: white;
}
.header {
position: fixed;
background-color: red;
width: 100%;
z-index: 2;
}
.container {
width: 100%;
height: 70%;
display: flex;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
margin: 0px;
outline: solid blue 1px;
}
<div class="container">
<div class="block1">
<div style="height:200px;">
<div class="header">ff</div>
<div style="height:500px;">
ff
</div>
</div>
</div>
<div class="block2">
<div style="height:200px;">
ff
</div>
</div>
</div>
【问题讨论】:
-
您尝试做的事情不会奏效,您需要重新考虑您的页面结构。在设计样式时,固定位置元素会从其父上下文中删除。你需要一个外部容器来指定两个元素的宽度来实现这一点。
标签: html css flexbox css-position