ÍøÂçѧԺ w3popÉçÇø ÍøÂç×ÊÔ´ ITÐÂÎÅ

w3pop.com :: ÍøÂçѧԺ :: WEBÉè¼Æ×ÛºÏ :: Êó±ê¾­¹ý¸Ä±ä±í¸ñ±³¾°ÊôÐÔ

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

WEBÉè¼Æ×ÛºÏ
¼æÈÝIE6/IE7/FFµÄ..
ʹÓÃcssÈÃÓ¢ÎÄÎı..
ÔÚÍøÒ³Éè¼ÆÖÐÑÕÉ«..
ÅúÁ¿Ïû³ýÍøÒ³Á¬½Ó..
display:inline-b..
25ÖÖÄܸÄÉÆ²¢Ìá¸ß..
³£ÓÃCSSËõдÓï·¨×..
marginÓÅ»¯µÄÒ»ÖÖ..
font-sizeµÄ¿ØÖÆ
div+css²¼¾ÖʱӦ×..
css¸ß¼¶²¼¾Ö¼¼ÇÉ
HTML rel ÊôÐÔ
ÓÃCSSʵÏÖÍøÒ³µÄ¾..
CSS³£ÓÃС¼¼ÇÉ
CSS±ÕºÏ¸¡¶¯ÔªËØ
ÓÃCSS¶¨Òå±êÌâµÄ¼..
×óÖÐÓÒ3À¸²¼¾ÖÖÐ×..
ÈçºÎÒÔ¼°ºÎʱʹÓÃ..
_blank¿ªÐ´°¿Ú²»..
CSSµÄÊ®°Ë°ã¼¼ÇÉ

Êó±ê¾­¹ý¸Ä±ä±í¸ñ±³¾°ÊôÐÔ


×÷Õß:Ades Tynyshov ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2007-05-10 ä¯ÀÀ:6636 :: ::

This tutorial will teach you how to make a menu like tables that will change background color when you mouseOver.

Õâ·Ý½Ì³Ì½«½Ì»áÄãÏÂÃæµÄ¼¼ÇÉ£ºµ±Êó±êÒÆÖÁ±í¸ñ£¨µ¥Ôª¸ñ£©ÉÏ·½Ê±£¬¸Ä±ä±í¸ñµÄ±³¾°ÑÕÉ«¡£

¸Ä±ä±í¸ñ±³¾°É« (Êó±êÒÆÖÁ±í¸ñÉÏ·½Ê±µÄЧ¹û)

1. First create your menu on your page. Then identify your two colors, one is for mouseOver and another one for initial color. In my case mouseOver color is: #999999 and initial color is: #CCCCCC

Ê×ÏÈ£¬ÔÚÄãµÄÒ³ÃæÉÏ´´½¨Ò»¸ö²Ëµ¥£»È»ºó£¬´´½¨Á½ÖÖÓÃÓÚ¼ø±ðµÄÑÕÉ«Ì壺һ¸öÊDZí¸ñµÄ³õʼÑÕÉ«£¬ÁíÒ»¸öÊÇÊó±êÒÆÖÁ±í¸ñÉÏ·½Ê±Ëù²úÉúµÄ±³¾°ÑÕÉ«¡£ÔÚÎÒÕâ¸ö°¸ÀýÖУ¬ÎÒËùĬÈÏʹÓõı³¾°Ð§¹ûÑÕÉ«£¨Êó±êÒÔÉÏȥʱ£©ÊÇ£º#999999£¬³õʼÑÕÉ«ÊÇ£º#CCCCCC¡£

2. Now copy this code to the head of you document. (Between <HEAD></HEAD> tags)

ÏÖÔÚ£¬½«ÏÂÃæÕâ¶Î´úÂë¸´ÖÆµ½ÎĵµÍ·²¿¡££¨Î»ÓÚ<HEAD></HEAD>±êǩ֮¼ä£©

<style type="text/css">

td.off {
background: #CCCCCC;
}

td.on{
background: #999999;
}

</style>

Change the color in blue with your own colors.

½«À¶É«¸Ä±äΪÄãËùÐèÒªµÄÑÕÉ«¡£

td.off will be our initial table color which is lighter gray #CCCCCC.

td.off
ÒâÖ¸±í¸ñµÄ³õʼÑÕÉ«£¬ÕâÀïÉèÖõijõʼֵÊÇ#CCCCCC¡£

td.on will be our changing color which is darger gray #999999.

td.on
ÒâÖ¸Êó±êÒÆ¶¯ÖÁ±í¸ñÉÏ·½Ê±ÏÔʾµÄÑÕÉ«£¬ÕâÀïÉèÖõÄÖµÊÇÉî»ÒÉ«£¨#CCCCCC£©¡£

3. Now we have to apply the CSS to the table that you have created. Insert the following code in every <td> tag inside your table. class="off" onmouseover="this.className='on'" onmouseout="this.className='off'"

ÏÖÔÚ£¬ÎÒÃÇÐèÒª×öµÄÊǽ«Õâ¶ÎCSS´úÂëÓ¦Óõ½ÒѾ­´´½¨µÄ±í¸ñÖС£½«ÏÂÃæÕâ¶Î´úÂë²åµ½±í¸ñÖеÄÿ¸ö<td>±êÇ©ÖС£“ class="off" onmouseover="this.className='on'" onmouseout="this.className='off'"

So your code should look like this:
¼ÓÈëºóµÄ´úÂëÈçÏÂËùʾ£º

<td class="off" onmouseover="this.className='on'" onmouseout="this.className='off'">MENU 1</td>

Let's go through the code one by one:
ÈÃÎÒÃÇÖðÐÐÀí½âÏÂÃæµÄÕâ¶Î´úÂ룺

1: <td class="off" - Assigns the off class of our CSS to the table column, which means initially the table column background will have a color of #CCCCCC

<td class="off"
—— Ϊ±í¸ñÖеÄÿÁе¥Ôª¸ñËù¶ÔÓ¦µÄCSSµÄoffÀำֵ£¬ËüµÄÒâ˼ÊÇ£º±í¸ñÿÁе¥Ôª¸ñµÄ³õʼÑÕÉ«ÊÇ£º#CCCCCC¡£

2: onmouseover="this.className='on'" - Assigns the on class of our CSS to the table column, when we mouseOver on it

onmouseover="this.className='on'"
——µ±Êó±êÒÆÖÁ±í¸ñÖеÄÿÁе¥Ôª¸ñÖ®ÉÏʱ£¬Ëù¶ÔÓ¦µÄCSSµÄЧ¹û¡£

3: onmouseout="this.className='off'"> - Assigns the off class of our CSS to the table column back, when we take away the mouse from it.

onmouseout="this.className='off'">
——µ±Êó±ê´Ó±í¸ñÖеÄÿÁе¥Ôª¸ñÉÏÒÆ¿ªÊ±£¬Ëù¶ÔÓ¦µÄCSSµÄЧ¹û¡£

4. Full Code
ÉÏͼʾÀýËù¶ÔÓ¦µÄÈ«²¿´úÂëÈçÏ£º

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Table Background Change</title>
<style type="text/css">
td.off {
background: #CCCCCC;
}
td.on {
background: #999999;
}
</style>
</head>
<body>
<table width="150" cellpadding="3">
<tr>
<td class="off" onmouseover="this.className='on'"
onmouseout="this.className='off'"><font color="#000000" size="1">Menu
1 </font></td>
</tr>
<tr>
<td class="off" onmouseover="this.className='on'"
onmouseout="this.className='off'"><font color="#000000" size="1">Menu
2 </font></td>
</tr>
<tr>
<td class="off" onmouseover="this.className='on'"
onmouseout="this.className='off'"><font color="#000000" size="1">Menu
3</font></td>
</tr>
<tr>
<td class="off" onmouseover="this.className='on'"
onmouseout="this.className='off'"><font color="#000000" size="1">Menu
4 </font></td>
</tr>
</table>
</body>
</html>

ÆÀÂÛ (1) 1 All