相关疑难解决方法(0)

body { overflow-x: hidden; } breaks position: sticky

I have an element that I am making sticky with position sticky:

#header {
    position: sticky;
    width: 100vw;
    top: 0;
}
Run Code Online (Sandbox Code Playgroud)
<app-header id="header"></app-header>
Run Code Online (Sandbox Code Playgroud)

And that works fine, but I realised that if I use:

body {
  overflow-x: hidden;
}
Run Code Online (Sandbox Code Playgroud)

That breaks sticky, and I need to set body overflow-x to hidden, how can I fix that, with only CSS solution, no JS solutions?

html css css-position

8
推荐指数
4
解决办法
3422
查看次数

标签 统计

css ×1

css-position ×1

html ×1