Home > Article > Web Front-end > How to set css height in js
How to set css height in js: 1. Modify the height of the div by modifying the style value of the div in the html file through js; 2. Use js to modify the height value of the div in the CSS file.
The operating environment of this article: Windows7 system, javascript1.8.5&&HTML5&&CSS3 version, Dell G3 computer.
How to set the height of div in js?
First open the editing tool we tested. I am using Eclipse here
We create a new test project and then Create a new index.html, basic.js and basic.css file
The first method is to modify the style value of the div in the html file using js to modify the height of the div HTML The file code in the file is as shown
After running, we see that the height of the two divs is the same. Next, we use js to modify the height
At this time we type the code in js to get the id of div1, use the style attribute corresponding to the css attribute and then set the height as shown in the picture
The second method is to use js to modify the height value of the div in the CSS file. The code in the HTML file is as shown in the figure
The code in the style sheet css file is as follows As shown in the picture, after running the project, you will see that the heights of the two divs are the same. I will not test it here
Then we get the id attribute of div1 in the js file Then use obj.style.cssTest to modify the embedded css
Then after running the project, the result is the same twice. The height of the div has changed
Recommended study: "css video tutorial"
The above is the detailed content of How to set css height in js. For more information, please follow other related articles on the PHP Chinese website!