css中模拟按钮的背景色改变

来源:百度知道 编辑:UC知道 时间:2024/06/17 16:45:43
我想做到效果是鼠标放在超链接上面,整个背景色都改变,而不只是文字的背景色改变了
我的代码如下 但是有问题
<!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>
<style type="text/css">
ul{list-style:none;font-weight:bold;}
li{float:left;margin:0px 10px;padding:5px 5px;background:#333333;}
li a{display:block;background:#333333;}
li a:link,li a:visited{text-decoration:none;color:#FF0000;}
li a:hover{text-decoration:none;color:#ffffff;background:#cccccc;}
</style>
</h

将li的padding值设为0,给a设一个padding值就可以了。

代码如下:

<!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>
<style type="text/css">
ul{list-style:none;font-weight:bold;}
li{float:left;margin:0px 10px;background:#333333;}
li a{display:block;background:#333333; padding:5px}
li a:link,li a:visited{text-decoration:none;color:#FF0000;}
li a:hover{text-decoration:none;color:#ffffff;background:#cccccc;}
</style>
</he