---
title: "(七)jquery总结：CSS "
author: "y8820960"
date: "2012-08-27T08:39:44Z"
tags: []
categories: ["Web前端"]
slug: "jquery-css"
draft: false
lastmod: "2012-08-24T15:34:29Z"
id: 1661810
url: "https://marvel00000.iteye.com/blog/1661810"
---

JQuery CSS 方法说明

css( name ) 访问第一个匹配元素的样式属性。  
css( properties ) 把一个”名/值对”对象设置为所有匹配元素的样式属性。  
$(”p”).hover(function () {  
$(this).css({ backgroundColor:”yellow”, fontWeight:”bolder” });  
}, function () {  
var cssObj = {  
backgroundColor: “#ddd”,  
fontWeight: “”,  
color: “rgb(0,40,244)”  
}  
$(this).css(cssObj);  
});  
css( name, value ) 在所有匹配的元素中，设置一个样式属性的值。  
offset( ) 取得匹配的第一个元素相对于当前可视窗口的位置。返回的对象有2个属性，  
top和left，属性值为整数。这个函数只能用于可见元素。  
var p = $(”p:last”);  
var offset = p.offset();  
p.html( “left: ” + offset.left + “, top: ” + offset.top );  
width( ) 取得当前第一匹配的元素的宽度值，  
width( val ) 为每个匹配的元素设置指定的宽度值。  
height( ) 取得当前第一匹配的元素的高度值，  
height( val ) 为每个匹配的元素设置指定的高度值。