首页 > 解决方案 > next.js 中的 div 高度不是 100%

问题描述

我在设置 next.js 中的页面时遇到问题。我想要全高页面。

因此,我在 body 和 html 标签中设置了 height 属性,没关系,我有 body 和 html 标签的全高(在开发工具中证明)但是虽然我将 #__next 高度设置为 100%,但我无法实现全高它。如果我应用 px 或 vh 等其他测量值,它就会受到影响。

布局.css

html {
  height: 100%;
  font-size: 16px;
}
body {
  min-height: 100%;
  font-family: @text-font-family;
  direction: rtl !important;
  text-align: start !important;
}
#__next {
height: 100%; // or min-height
}

HTML DOM

标签: htmlcssnext.js

解决方案


position: absolute;可能对你有用

html,
body {
  margin: 0;
}

#__next {
  background: blue;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}
<div id="__next"></div>


推荐阅读