3 回答
TA贡献1860条经验 获得超9个赞
在这里(全屏查看以进行可视化):
body {
margin: 0;
}
.main {
display: flex;
flex-direction: column;
align-items: center;
background: #e8e8e8;
border: 1px solid #000;
margin: 0px;
box-sizing: border-box;
}
.container {
display: flex;
flex-direction: column;
max-width: 300px;
width: 100%;
}
.parent {
display: flex;
/* flex-direction: column; */
width: 100%;
background-color: #e9cccc;
box-sizing: border-box;
position: sticky;
top: 0;
}
.fit {
height: 50px;
}
.full {
background-color: #d1ccd8a6;
border: 1px solid #666;
border-radius: 3px;
height: 50px;
padding: 0px;
box-sizing: border-box;
}
.full1 {
position: absolute;
width: 100%;
left: 0px;
top: 0px;
}
.full2 {
width: 100vw;
position: relative;
left: calc(-50vw + 50%);
}
.full3 {
position: relative;
width: 200%;
left: -50%;
}
.full4 {
margin-left: calc(-50vw + 50%);
width: 100vw;
}
.full5 {
width: 100vw;
position: relative;
left: 50%;
right: 50%;
margin-left: -50vw;
margin-right: -50vw;
}
.full6 {
margin-left: calc(-50vw + 50%);
width: 100vw;
}
.hide {
display: none;
}
<div class="main">
<div class="container">
<div class="fit">
something 1
</div>
<div class="parent">
<header class="full full1 hide">
child full1
</header>
<header class="full full2 hide ">
child full2
</header>
<header class="full full3 hide">
child full3
</header>
<header class="full full4 hide">
child full4
</header>
<header class="full full5">
child full5
</header>
<header class="full full6 hide">
child full6
</header>
</div>
<div class="fit">
something 2
</div>
</div>
</div>
TA贡献1796条经验 获得超4个赞
这是你想要的吗?
我刚刚更改了您的 CSS .main,.parent并且.full-5
body: {
margin: 0px;
}
.main {
display: flex;
flex-direction: column;
align-items: center;
background: #e8e8e8;
border: 1px solid #000;
margin: 0px;
box-sizing: border-box;
position: relative;
}
.container {
display: flex;
flex-direction: column;
max-width: 300px;
width: 100%;
}
.parent {
display: flex;
/* flex-direction: column; */
width: 100%;
background-color: #e9cccc;
box-sizing: border-box;
top: 0;
height: 50px;
}
.fit {
height: 50px;
}
.full {
background-color: #d1ccd8a6;
border: 1px solid #666;
border-radius: 3px;
height: 50px;
padding: 0px;
box-sizing: border-box;
}
.full1 {
position: absolute;
width: 100%;
left: 0px;
top: 0px;
}
.full2 {
width: 100vw;
position: relative;
left: calc(-50vw + 50%);
}
.full3 {
position: relative;
width: 200%;
left: -50%;
}
.full4 {
margin-left: calc(-50vw + 50%);
width: 100vw;
}
.full5 {
position: absolute;
left: 0;
right: 0;
}
.full6 {
margin-left: calc(-50vw + 50%);
width: 100vw;
}
.hide {
display: none;
}
<div class="main">
<div class="container">
<div class="fit">
something 1
</div>
<div class="parent">
<header class="full full1 hide">
child full1
</header>
<header class="full full2 hide ">
child full2
</header>
<header class="full full3 hide">
child full3
</header>
<header class="full full4 hide">
child full4
</header>
<header class="full full5">
child full5
</header>
<header class="full full6 hide">
child full6
</header>
</div>
<div class="fit">
something 2
</div>
</div>
</div>
- 3 回答
- 0 关注
- 113 浏览
添加回答
举报