jquery css类

$(selecor).css(name)

css()方法返回或设置匹配元素的一个或多个样式属性。

设置<p>元素的颜色:

Java代码   收藏代码
  1. $(".button").click(function(){  
  2.   $("p").css("color","blue");  
  3. });  

 使用函数来设置css属性

Java代码   收藏代码
  1. $(selector).css(name,function(index,value))  
  2. //index 为元素在对象集合中的索引位置,value 是原先的属性值。  

 例如将所有段落的颜色设为红色

Java代码   收藏代码
  1. $("button").click(function(){  
  2.     $("p").css("color",function(){return "red";});  
  3.     });  

 逐渐增加div的宽度

Java代码   收藏代码
  1. $("div").click(function() {  
  2.   $(this).css(  
  3.     "width", function(index, value) {return parseFloat(value) * 1.2;}  
  4.   );  
  5. });  

 设置多个css属性

Java代码   收藏代码
  1. $(selector).css({property:value, property:value, ...})  

 例如

Java代码   收藏代码
  1. $("button").click(function(){  
  2.     $("p").css({  
  3.       "color":"white",  
  4.       "background-color":"#98bf21",  
  5.       "font-family":"Arial",  
  6.       "font-size":"40px",  
  7.       "padding":"5px"  
  8.     });  
  9.   });  
  10. });  

 jQuery width(),height()

width() 方法设置或返回元素的宽度(不包括内边距、边框或外边距)。

 height() 方法设置或返回元素的高度(不包括内边距、边框或外边距)。

Java代码   收藏代码
  1. $("button").click(function(){  
  2.   var txt="";  
  3.   txt+="Width: " + $("#div1").width() + "</br>";  
  4.   txt+="Height: " + $("#div1").height();  
  5.   $("#div1").html(txt);  
  6. });  
  7.  
 增加整个页面的背景色 增加雪白色
body{
“background-color” :snow;
}
 

猜你喜欢

转载自liujun11.iteye.com/blog/2389518