用CSS实现网页中鼠标交互的方法
2007-06-26 11:51
477 查看
我们浏览网页的时候,经常会遇到一些交互的效果。例如容器在鼠标移上去的时候,会发生一些变化。这些效果,可以用多种方法来实现。现在我们要解决的是如何在CSS中写脚本实现交互效果。
CSS代码如下:
.show {
width:600px;
height:58px;
margin:50px auto 0 auto;
line-height:58px;
border:1px solid #c00;
background:#f0f0f0;
text-align:center;
/*chinahtml.com提醒您重点注意查看下面的代码*/
event:expression(
onmouseover = function()
{
this.style.backgroundColor='#ccc'
this.style.border='1px solid #000'
},
onmouseout = function()
{
this.style.backgroundColor='#f0f0f0'
this.style.border='1px solid #c00'
}
)
}
HTML代码:
<div class="show">cnwebshow.com </div>
这段代码的意思是定义了鼠标的两种不同的状态,onmouseover、onmouseout,在两种不同的状态下,对元素应用不同的样式设置。这样就达到了我们想要的交互效果。
代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>www.chinahtml.com展示</title>
<style type="text/css">
<!--
.show {
width:600px;
height:58px;
margin:50px auto 0 auto;
line-height:58px;
border:1px solid #c00;
background:#f0f0f0;
text-align:center;
/*提醒您重点注意查看下面的代码*/
event:expression(
onmouseover = function()
{
this.style.backgroundColor='#ccc'
this.style.border='1px solid #000'
},
onmouseout = function()
{
this.style.backgroundColor='#f0f0f0'
this.style.border='1px solid #c00'
}
)
}
-->
</style>
</head>
<body>
<div class="show">chinahtml.com </div>
</body>
</html>
CSS代码如下:
.show {
width:600px;
height:58px;
margin:50px auto 0 auto;
line-height:58px;
border:1px solid #c00;
background:#f0f0f0;
text-align:center;
/*chinahtml.com提醒您重点注意查看下面的代码*/
event:expression(
onmouseover = function()
{
this.style.backgroundColor='#ccc'
this.style.border='1px solid #000'
},
onmouseout = function()
{
this.style.backgroundColor='#f0f0f0'
this.style.border='1px solid #c00'
}
)
}
HTML代码:
<div class="show">cnwebshow.com </div>
这段代码的意思是定义了鼠标的两种不同的状态,onmouseover、onmouseout,在两种不同的状态下,对元素应用不同的样式设置。这样就达到了我们想要的交互效果。
代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>www.chinahtml.com展示</title>
<style type="text/css">
<!--
.show {
width:600px;
height:58px;
margin:50px auto 0 auto;
line-height:58px;
border:1px solid #c00;
background:#f0f0f0;
text-align:center;
/*提醒您重点注意查看下面的代码*/
event:expression(
onmouseover = function()
{
this.style.backgroundColor='#ccc'
this.style.border='1px solid #000'
},
onmouseout = function()
{
this.style.backgroundColor='#f0f0f0'
this.style.border='1px solid #c00'
}
)
}
-->
</style>
</head>
<body>
<div class="show">chinahtml.com </div>
</body>
</html>
相关文章推荐
- CSS 网页表单实现鼠标悬停交互效果
- 网页设计制作CSS实现隔行换色两种方法
- JS实现网页滚动条感应鼠标变色的方法
- CSS针对IE6实现网页图片底部留出空白的方法
- JS实现禁止用户使用Ctrl+鼠标滚轮缩放网页的方法
- javascript+css 网页每次加载不同样式的实现方法
- 纯CSS实现鼠标悬停提示的方法
- 用CSS来改变网页鼠标显示样式的方法
- JS+CSS实现感应鼠标渐变显示DIV层的方法
- JS实现鼠标滑过链接改变网页背景颜色的方法
- 实现鼠标经过背景变色的方法有很多,今天我们介绍的是用CSS+DIV实现的方法。
- CSS垂直居中网页布局实现的5种方法
- 鼠标拖动改变DIV等网页元素的大小的实现方法
- DIV始终固定在网页右下角位置的CSS实现方法,返回顶部功能
- CSS垂直居中网页布局实现的5种方法
- js中的事件响应,实现网页交互,鼠标点击、经过等
- 在网页中引用DWG控件,交互绘图,和响应鼠标点击对象的方法
- js+css实现禁止鼠标右键与选中网页文字
- 用idhttp post 方法发送数据到服务器上。实现数据和网页的交互。
- jQuery实现鼠标单击网页文字后在文本框显示的方法