js如何改变css样式
导读:收集整理的这篇文章主要介绍了js如何改变css样式,觉得挺不错的,现在分享给大家,也给大家做个参考。js改变css样式的方法:1、使用cssText方法;2、使用【setPRoPErty( 】方法;3、使用css属性对应的style属性。本...
收集整理的这篇文章主要介绍了js如何改变css样式,觉得挺不错的,现在分享给大家,也给大家做个参考。js改变css样式的方法:1、使用cssText方法;2、使用【setPRoPErty()】方法;3、使用css属性对应的style属性。
本教程操作环境:windows7系统、css3版,DELL G3电脑。
js改变css样式的方法:
第一种:用cssText
div.style.cssText='width:600px; height:250px; border:1px red solid; text-align: center; line-height: 250px; ';
第二种:用setProperty()
div.style.setProperty('width','700px'); div.style.setProperty('height','300px'); div.style.setProperty('line-height','300px'); div.style.setProperty('background','#f00'); div.style.setProperty('color','#fff'); div.style.setProperty('border','1px solid blue'); div.style.setProperty('text-align','center');
第三种:使用css属性对应的style属性
div.style.width = "800px"; div.style.height = "250px"; div.style.lineHeight = "250px"; div.style.background = "#000"; div.style.color = "#fff"; div.style.border = "1px solid #111"; div.style.textAlign = "center";
body> div id="div"> 这是一个盒子/div> script type="text/javascript"> VAR div = document.getElementById("div"); //第一种:用cssText div.style.cssText='width:600px; height:250px; border:1px red solid; text-align: center; line-height: 250px; '; //第二种:用setProperty() div.style.setProperty('width','700px'); div.style.setProperty('height','300px'); div.style.setProperty('line-height','300px'); div.style.setProperty('background','#f00'); div.style.setProperty('color','#fff'); div.style.setProperty('border','1px solid blue'); div.style.setProperty('text-align','center'); //第三种:使用css属性对应的style属性 div.style.width = "800px"; div.style.height = "250px"; div.style.lineHeight = "250px"; div.style.background = "#000"; div.style.color = "#fff"; div.style.border = "1px solid #111"; div.style.textAlign = "center"; /script> /body>
相关教程推荐:CSS视频教程
以上就是js如何改变css样式的详细内容,更多请关注其它相关文章!
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: js如何改变css样式
本文地址: https://pptw.com/jishu/589043.html