html鼠标悬浮在按钮上,让按钮背景变色

写一下代码。写的要值这个分。

1、首先创建一个新的html文件,如图所示。

2、在html文件上找到body标签,在这个标签里创建一个div标签并设置class类为bg ,如图所示。

3、接着在title标签后创建style标签用来给bg类添加样式。在这给bg类设置了一个宽、高和背景颜色。

4、然后设置鼠标滑过div时背景变色。给bg样式类添加鼠标滑过:hover,然后设置鼠标滑过时的背景颜色。

5、最后实用浏览器打开,保存好html后使用浏览器打开,在鼠标没有滑过div时背景是红色的,当鼠标滑过div的时候背景从红色变为了棕色。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-01-12

鼠标放在button上改变颜色,HTML

<button onmouseover="this.style.backgroundColor='red';" 
onmouseout="this.style.backgroundColor='';" >确定</button>

第2个回答  推荐于2018-02-22
把下面代码直接保存为.html后缀名就可以了。。。记得给分就是了
<!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/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<style>
.adminbutton {border:#07A1EE 1px solid;background:#BFE7FA; height:22px;}
</style>
<body><br><br><br>
<center>
<input type="button" name="SubmitS" value=" 按 钮 " class="adminbutton" onMouseOut="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='#efefef'" style="height:18px;padding-top:1px; width:">
</center>
</body>
</html>本回答被提问者和网友采纳