HTML元素的style属性
- 通过
getAttribute()、setAttribute()和removeAttribute()
方法,直接读写删除元素的style属性 style
本身是一个对象,部署了CSSStyleDeclaration
接口,可以直接读写属性e.style.fontSize = "18px";
e.style.color = "yellow";
CSSStyleDeclaration 接口
简介
该接口用来操作元素的样式,共有三个地方部署了这个接口
- 元素节点的
style
属性(Element.style) CSSStyle
实例的style
属性window.getComputedStyle()
的返回值
- 该接口可以直接读写CSS的样式属性,但是连接号需要变成驼峰法
Element.style只能返回行内样式;元素的全部样式需要window.getComputedStyle()来返回
CSSStyleDeclaration实例属性
cssText
判断元素的
style
对象的某个属性值是否为字符串typeof element.style.transform === "string";
CSS.supports()
判断当前环境是否支持某一句CSS规则
CSS.supports('transform-origin','5px');
window.getComputedStyle()
该方法返回浏览器计算后得到的最终规则
- 接收一个节点为参数
- 返回一个CSSStyleDeclaration实例
- 该方法返回的CSSStyleDeclaration实例的cssText属性无效
- 该方法也可以接收第二个参数,表示当前元素的伪元素(比如::before,:after,:first-line)等
StyleSheet接口
CSSStyleRule接口