jQuery使用手册之CSS操作
Jquery对css的操作相当方便,能很方便我们去通过js修改css。传统javascript对css的操作相当繁琐,比如
<div id="a" style="background:blue">css</div>
取它的background语法是:
document.getElementById("a").style.background
而jQuery对css更方便的操作:
$("#a").background();$("#a").background(“red”)
说明如下
$("#a")得到jQuery对象[ <div id="a" … /div> ]
$("#a").background()将取出该对象的background样式。
$("#a").background(“red”)将该对象的background样式设为redjQuery提供了以下方法,来操作css:
background ()
background (val)
color()
color(val)
css(name)
css(prop)
css(key, value)
float()
float(val)
height()
height(val)
width()
width(val)
left()
left(val)
overflow()
overflow(val)
position()
position(val)
top()
top(val)
这里需要讲解一下css(name);css(prop);css(key, value),其他的看名字都知道什么作用了!
<div id="a" style="background:blue; color:red">css</div><P id="b">test</P>
css(name):获取样式名为name的样式
$("#a").css("color"):将得到样式中color值red,("#a").css("background ")将得到blue
css(prop):prop是一个hash对象,用于设置大量的css样式
$("#b").css({ color: "red", background: "blue" });
最终效果是
<p id="b" style="background:blue; color:red">test</p>
{ color: "red", background: "blue" },hash对象,color为key,"red"为value,
css(key, value) 用于设置一个单独得css样式
$("#b").css("color","red");
最终效果是
<p id="b" style="color:red">test</p>
相关文档:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>双色表格CSS实例</title>
<style type="text/css">
#DataGrid1 tr {
background-color: expression(
this.sectio ......
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
body{position:relative; border:solid 1px #30F; height:600px; }
.box{ position:ab ......
JavaScript作用小结:
1 创建脚本块
1: <script language=”JavaScript”>
2: JavaScript code goes here
3: </script>
2 隐藏脚本代码
1: <script language=”JavaScript”>
2: <!--
3: document.write(“ ......
Css 图解margin 和 padding 的区别
以前常常以为margin 和 padding的区别,而老是google,现在理清了...
图解:
margin : 相当于组件的 外边缘 与外部组件的距离
padding : 相当于组件的 内边缘 与内部组件的距离 ......
由于浏览器版本的不同,对CSS里某些元素的解释也不一样,才子当然也碰到同样的问题,也收集了一些解决方法,才子之前贴过两个针对浏览器版本不同而选择不同CSS的代码,有兴趣的朋友自己找找吧。
其实我们还可以利用条件注释的方法来达到类似的目的,什么是条件注释,才子也在此简单介绍一下,无非就是一些if判断啦,呵呵, ......