【问题标题】:How do i remove the div with id="__next" in Next.js如何在 Next.js 中删除 id="__next" 的 div
【发布时间】:2021-10-09 20:25:25
【问题描述】:

我正在使用 Next.js 创建一个网站。我想要一个带有position: sticky; 行为的标题。

但是,Next.js 会在未经我许可的情况下自动在我的网站根目录生成一个属性为 id="__next" 的 div。

我需要删除该 div,以便我的标头的 position: sticky; 行为可以按照预期的方式工作。我该怎么做?

【问题讨论】:

  • 为什么不直接将position: relative; 添加到__next 元素中?
  • this 有帮助吗?
  • 接下来需要它来安装您的应用程序...
  • __next id 是渲染应用所必需的,您可以随时添加一些样式来实现粘性行为
  • 这与要求在 react 中删除 root 相同。 Nextjs 需要它来渲染你的网页。

标签: javascript html reactjs next.js


【解决方案1】:

您无法删除它,next.js 需要它来呈现您的 Web 应用程序。 position: sticky 总是寻找它的父元素的高度。您可以将height: 100%; position: relative; 分配给__Next id。所以,它将作为身体工作。然后,您的位置粘性将起作用。

【讨论】:

    【解决方案2】:
    body {
      display: flex;
      min-height: 100vh;
    }
    
    #__next {
      flex: 1 1 auto;
    }
    
    // do whatever you want here and it'll work as expected
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-25
      • 1970-01-01
      • 1970-01-01
      • 2014-08-06
      • 1970-01-01
      • 2011-06-03
      • 1970-01-01
      相关资源
      最近更新 更多