如何防止粘性元素移到页眉后面?
当前的代码片段在父对象上使用填充顶部,我也try 在附加子对象上使用边距-顶部,或者在50px的透明边框上使用边框,但似乎不起作用.
我知道在这种情况下我可以很容易地在粘性上使用top: 50px;
,但我想将这一部分集成到一个Reaction组件中,使用特定的大小会使组合不同的组件变得更加困难,因为它们都必须共享最大的大小.
我怎样才能使表头/填充物"结实",使粘性的东西无法通过?
body{
background: rgb(200,200,200);
padding:0px;
margin:0px;
}
header{
height: 50px;
font-size: 2em;
background: aqua;
opacity: 0.6;
text-align:center;
position: fixed;
width: 100%;
}
.content-wrapper{
padding-top: 50px; /* keeps the header space */
height: 800px; /*for demo*/
}
.sticky{
position: sticky;
top:0;
}
<header>header</header>
<div class="content-wrapper">
<div class="sticky">
Hello, I am a sticky element
<div>
<div>