JS如何操作css中float属性写法

前端APP 投稿 10100 0 评论

JS如何操作css中float属性写法

我们都知道使用js操作css属性的写法是有一定的规律的,对于没有中划线的css属性一般直接使用 style.属性名 即可,如:obj.style.margin,obj.style.width,obj.style.left,obj.style.position 等。对于含有中划线的css属性,将每个中划线去掉并将每个中划线后的第一个字符换成大写即可。如:obj.style.marginTop,obj.style.borderLeftWidth,obj.style.zIndex,obj.style.fontFamily等。但在css中有一个特殊的属性,其js使用方法比较特殊。这个特殊的属性就是 float 属性。

如果按照常规写法,obj.style.float 这种写法是错误的。在任何浏览器中都将不会生效。那么这个属性该如何用js来写了。

其正确的使用方法如:

IE浏览器中:

obj.style.styleFloat

其他浏览器:

obj.style.cssFloat

编程笔记 » JS如何操作css中float属性写法

赞同 (52) or 分享 (0)
游客 发表我的评论   换个身份
取消评论

表情
(0)个小伙伴在吐槽