读写样式属性
elem.style.xxx
.box{width: 200px;}<div class='box'></div>var oDiv=document.getElementsByTagName('div');此时访问oDiv.style.width 结果为空,也证实了DOM不能操作cssoDiv.style.width='200px';此时再访问就可以得到200px了复合值要拆分赋值

保留字要加’css’: oDiv.style.cssFloat=’left’
查看css属性的方法:oDIv.style
查看计算样式:ie8一下不支持 elem.currentStyle
查看计算属性的封装方法
function getStyles(elem,prop){if(window.getComputedStyle){if(prop){return window.getComputerStyle(elem,null)[prop];}else{return window.getComputedStyle(elem,null);}}else{if(prop){return elem.currentStyle[prop];}else{return elem.currentStyle;}}}oDiv.onclick=function(){//var width=this.offsetWidth; offset会加上padding等其他数据,所有一般都不用var width=parseInt(getStyle(this.'width'));this.style.width=width+'10'+'px';}
offsetWidth、offsetHeight
odiv.offsetWidth //可以计算出div元素的宽高
HTMLElement.offsetWidth是一个只读属性,返回一个元素的布局宽度,offsetWidth是测量包含元素的边框(border)、水平线上的内边距(padding)、竖直方向滚动条(scrollbar)(如果存在的话)、以及CSS设置的宽度(width)的值。
计算伪元素的方法
div::after {content: "";display: block;width: 50px;height: 50px;background-color: pink;}var oDiv=document.getElementsByTagName('div')[0];window.getComputedStyle(div,'after').width //'50px'


