1

I'm building a React app, and I'm having a problem with position: sticky in my story-header element. I already checked the parent styles and there's no overflow: hidden attribute-value.

HTML

<div className='StoryList' >
    <div className='story-header'></div>
</div>

CSS - Stylesheet

.App {
    width: 100%;
    overflow: visible;
}
.StoryList {
    position: relative;
    margin: 0;
    width: 100%;
}
.story-header {
    width: 100%;
    top: -20px;
    height: 50px;
    left: 0;
    background-color: lightgray;
    position: sticky;
    z-index: 1;
}

Why is the story-header sliding above the top?

AlleyOOP
  • 1,536
  • 4
  • 20
  • 43

3 Answers3

1

I'm not sure that I understood you correctly, but it works as it should. I've tried it in pure html/css and it's working. Check my code, buddy:

.App {
    width: 100%;
    height: 200vh;
    overflow: visible;
}

.StoryList {
    background: #000;
    height: 40vh;
    position: fixed; // you can comment it out, I'm not sure what would you like to have
    margin: 0;
    width: 100%;
}

.story-header {
    width: 100%;
    top: -20px;
    height: 50px;
    left: 0;
    background-color: lightgray;
    position: sticky;
    z-index: 1;
}

Check both versions - with fixed position and without it.

kaziutus
  • 138
  • 3
  • 10
1

well i am also having the same problem turns out i need to set the height of the app and root to inherit, trying doing it and it should work then

  • 1
    Please be more precise, add your code. See [How To Answer](https://stackoverflow.com/help/how-to-answer) – jasie Sep 16 '20 at 06:00
0

It is may be very strange, but in my case the deleting of the font-size: 100%; and the font-size: inherit; in the zero-styles helped me to solve the issue!