如果一个元素的祖先元素的高度小于 100%,有没有办法在不使用 JS 的情况下仍然使它成为浏览器的高度 window?

If an element has ancestors with heights < 100%, is there a way to still make it the height of the browser window without using JS?

也许有一种方法可以计算出浏览器的高度并将其用作 sass 中的变量?或者也许是某种只考虑 window 本身的绝对定位?

根据您的用例,您可能需要查看 vh 单元。该单位允许您指定相对于浏览器高度的高度。例如,50vh 将是 window 高度的 50%。

vw 也可用于 window 宽度。

你可以看看this举例

单位好像是supported across the main used browser

是的。

您可以使用 position: fixed; 作为初学者,这将固定元素相对于 window 然后 height: 100% 将使其占据 window 的完整高度.但是,此选项将使元素脱离滚动。

第二种方法是在 <html><body> 标签上设置 position: relative;,然后确保 DOM 树下的所有元素都指向目标元素默认为 position: static;。最后,在目标元素上设置 position: absolute;position: relative; 将使其引用树中未设置为静态的下一个元素。

更多关于职位的信息 at MDN and CSS Tricks

我最后的方法是使用 vh 单位。该单位是当前视口高度的 1%,因此值 100 将使元素成为屏幕高度的 100%。 Support is not perfect,所以提供后备。

最后,sass 是一种预编译语言,永远不会到达浏览器。它生成 css,然后由浏览器使用,并用于为我们的 css 编程添加功能。