简体   繁体   中英

Set min-height property with pure Javascript

I am trying to set an inline style property of a div using javascript. This seems to work to get the value to an alert window:

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

However, this does not set the style for the div with the ID used:

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

Neither does this:

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

Any help would be appreciated.

Use camelCasing for CSS styles in JS

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

You're close. The property is camel-cased without a hyphen, like:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM