---
title: "js操作css的规则"
author: "rubyol"
date: "2010-09-01T13:11:10Z"
tags: []
categories: ["Web前端"]
slug: "js-css"
draft: false
lastmod: "2010-09-01T13:11:10Z"
id: 752572
url: "https://rubyol.iteye.com/blog/752572"
---

书写规则：

 

1、没有中划线的css属性，直接使用“style.属性名”即可。  
如：obj.style.width，obj.style.left 等。

 

2、含有中划线的css属性，去掉中划线并将中划线后的那个字符大写即可。  
如：obj.style.zIndex，obj.style.fontFamily 等。

 

3、特殊属性:float，不能直接使用obj.style.float，这样操作是无效的。正确的使用方法是：IE:obj.style.styleFloat，其他浏览器:obj.style.cssFloat。