1、首先新建一个html文件,命名为test.html,在test.html文件内,使用table标签创建一个表格,用于测试。
2、在test.html文件内,设置table标签的class属性为mytable,同时设置边框为1px。
3、接着在css标签内,通过class设置表格的样式,定义它的宽度为300px,高度为200px。
4、在css标签内,通过td元素名称和“:hover”选择器定义当鼠标指向单元格时,改变单元格的背景颜色,设置为红色。
5、最后在浏览器打开test.html文件,鼠标经过之后,即可变色。
参照以下代码:
写在标签内的鼠标经过的语句。
<p>查找更多代码,.borderColor之类的前面一定要有style,因为是改变行内样式,如果是classname就不用,如onMouseOut="this.style.background='url(image/login_2.jpg)'" ,一定要'url()',不然出错。
<div class="cbt2" onMouseOver="this.className='cbt1'" onMouseOut="this.className='cbt2'"><span class="btsue" onMouseOver=" this.style.color='#FFFFFF'" onMouseOut="this.style.color='#0066cc'" >确 认</span></div>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<div style="width:100pxheight:35pxbackground:#CCCtext-align:centerline-height:35pxfont-size:12pxcursor:pointer" onmouseout="this.style.background='#ccc'" onmousemove="this.style.background='#f00'">
<a href="#" target="_blank">首页</a>
</div>
<div style="width:100pxheight:35pxbackground:#CCCtext-align:centerline-height:35pxfont-size:12pxcursor:pointer" onmouseout="this.style.background='#ccc'" onmousemove="this.style.background='#f00'">
<a href="#" target="_blank">首页</a>
</div>
<div style="width:100pxheight:35pxbackground:#CCCtext-align:centerline-height:35pxfont-size:12pxcursor:pointer" onmouseout="this.style.background='#ccc'" onmousemove="this.style.background='#f00'">
<a href="#" target="_blank">首页</a>
</div>
<div style="width:100pxheight:35pxbackground:#CCCtext-align:centerline-height:35pxfont-size:12pxcursor:pointer" onmouseout="this.style.background='#ccc'" onmousemove="this.style.background='#f00'">
<a href="#" target="_blank">首页</a>
</div>
</body>
</html>