使用纯Javascript设置最小高度属性

Set min-height property with pure Javascript

本文关键字:小高 高度 属性 设置 Javascript      更新时间:2023-09-26

我正在尝试使用javascript设置div的内联样式属性。这似乎可以使警报窗口的值生效:

<!-- /returns 890px for me -->
<script>
  alert(screen.height - 10 +"px");
</script>

然而,这并没有为使用ID的div设置样式:

<script>
document.getElementById("page-wrapper").style.min-height = screen.height - 10 +"px";
</script>

这也不是:

<script>
    document.getElementById("page-wrapper").style.min-height = screen.height - 10 +"px";
</script>

如有任何帮助,我们将不胜感激。

在JS 中为CSS样式使用camelCasing

<script>
    document.getElementById("page-wrapper").style.minHeight = screen.height - 10  +"px";
</script>

你很接近。该属性是不带连字符的驼色大小写,如:

<script>
    document.getElementById("page-wrapper").style.minHeight = screen.height - 10 + "px"
</script>