网页制作技巧

      电脑世界 2005-4-13 9:45
2.如何改变字的颜色
   在有些网页我们可以看到,当MOUSE移上去是一种颜色,移开就是另外一种颜色,这是怎么样实现的呢?这里我们就来看一看。

  这里我们只需要在Head内预先定义两个类,分别定义了两种颜色,这在后面的HTML源文件中会用到这个颜色的定义:

  <style>
   .normal {color:red;}
   .start {color:blue;}
  </style>

  然后我们在要改变的字前后加上下面的代码:

  <SPAN onmouseover = "this.className = 'normal'" 
   onmouseout = "this.className='start'" class=start> here </SPAN>

   这里的“class=start”是将这行字的默认值设为 start {color:blue;},要是不加上这句 的话,你这行字的颜色就会变成HTML预先设定的数值。

  下面我们看一看效果。当我们把鼠标移动到“here”上的时候,颜色为“normal”定义的颜色,而当鼠标移开的时候“here”的颜色为“start”定义的颜色。

  试者将鼠标挪到“here”,观看效果。(注意这种效果只有在Internet Explorer下才可以看到)
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}