Get the App
SLTechnology News&Howtos  ›  Development  › 

Modify the style of html body in js

Shulou Source: shulou.com Published: 2022-06-02 16:28:23 09月12日 Update

In this issue, the editor will bring you about what is the style of modifying html body in js. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

I. original definition

First define it in css: body, html width and height is 300px

Body, html {width: 300px; height: 300px;}

Second, js operation, take modifying width as an example

/ / get body, html node style (mainly html here, it is not clear how to get it at first) let bodyStyle = document.body.stylelet htmlStyle = document.getElementsByTagName ('html') [0] .style / / get the width of the browser Width can also be set to any value let width = document.documentElement.clientWidth | | document.body.clientWidth// reset body width bodyStyle.width = `${width} px` / / reset html width htmlStyle.width =` ${width} px` / / or other style modifications, such as: htmlStyle ['min-width'] = `${width} px` 3. Effect: width has been modified

The above is what the editor shares with you to modify the style of html body in js. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Tags: Width style content analysis original clear professional small and medium rich in content that is effects articles methods more browsers knowledge articles nodes industries perspectives Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Tech Info Docker Microsoft MariaDB