CSS的一些实用例子

// 结合脚本语言动态的控制元素在页面中出现的位置。

Code:
  1.   
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">   
  3. <html>   
  4.     <head>   
  5.         <title>css11.html</title>   
  6.         <meta http-equiv="content-type" content="text/html; charset=UTF-8">   
  7.         <style type="text/css">   
  8.         <!--   
  9.           div.show{   
  10.                 position:absolute;   
  11.                 top:10;   
  12.                 left:200;   
  13.                 visibility:visible;   
  14.             }   
  15.           div.hide{   
  16.                 position:absolute;   
  17.                 top:120;   
  18.                 left:200;   
  19.                 visibility:hidden;   
  20.             }   
  21.         -->   
  22.         </style>   
  23.   
  24.     </head>   
  25.   
  26.     <body>   
  27.         <div class="hide">     //将不显示
  28.             <img src="smile.gif" alt="">   
  29.         </div>   
  30.         <div class="show">   
  31.             <img src="cry.gif" alt="">   
  32.         </div>   
  33.   
  34.     </body>   
  35. </html>  

 【注】div块标记,该标记可以将其内部的图片及文字作为一个整体,及分层进行控制,往往可以实现页面效果的局部改变。

 ##CSS中的cursor属性改变鼠标指针的形状。

Code:
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">   
  2. <html>   
  3.     <head>   
  4.         <title>css12.html</title>   
  5.         <meta http-equiv="content-type" content="text/html; charset=UTF-8">   
  6.         <style type="text/css">   
  7.         <!--   
  8.             .hand{cursor:hand;}         /*手形*/   //==》class属性值
  9.             .crosshair{cursor:crosshair;}           /*精确定位“+”字*/  
  10.             .move{cursor:move;}         /*移动*/  
  11.             .e-resize{cursor:e-resize;}     /*箭头朝右方*/  
  12.             .ne-resize{cursor:ne-resize;}           /*箭头朝右上方*/  
  13.             .nw-resize{cursor:nw-resize;}           /*箭头朝左上方*/  
  14.             .n-resize{cursor:n-resize;}     /*箭头朝上方*/  
  15.             .se-resize{cursor:se-resize;}           /*箭头朝右下方*/  
  16.             .s-resize{cursor:s-resize;}     /*箭头朝下方*/  
  17.             .w-resize{cursor:w-resize;}     /*箭头朝左方*/  
  18.             .text{cursor:text;}         /*“I”字型*/  
  19.             .wait{cursor:wait;}         /*等待*/  
  20.             .help{cursor:help;}         /*帮助*/  
  21.         -->   
  22.         </style>   
  23.   
  24.     </head>   
  25.   
  26.     <body>   
  27.         <p class="hand">   
  28.             Give me a hand!(手形)   
  29.         </p>   
  30.         <p class="crosshair">   
  31.             Give me a crosshair(精确定位)!   
  32.         </p>   
  33.         <p class="move">   
  34.             Give me a Move(移动)!   
  35.         </p>   
  36.         <p class="e-resize">   
  37.             Give me a e-resize(箭头方向朝右)!   
  38.         </p>   
  39.         <p class="ne-resize">   
  40.             Give me a ne-resize(箭头方向朝右上)!   
  41.         </p>   
  42.         <p class="nw-resize">   
  43.             Give me a nw-resize(箭头方向朝左上)!   
  44.         </p>   
  45.         <p class="n-resize">   
  46.             Give me a n-resize(上)!   
  47.         </p>   
  48.         <p class="se-resize">   
  49.             Give me a se-resize(左下)!   
  50.         </p>   
  51.         <p class="s-resize">   
  52.             Give me a s-resize(下)!   
  53.         </p>   
  54.         <p class="w-resize">   
  55.             Give me a w-resize(左)!   
  56.         </p>   
  57.         <p class="text">   
  58.             Give me a text(文本)!   
  59.         </p>   
  60.         <p class="wait">   
  61.             Give me a wait(等待)!   
  62.         </p>   
  63.         <p class="help">   
  64.             Give me a help(帮助)!   
  65.         </p>   
  66.   
  67.     </body>   
  68. </html>  

//-------css+javascript 脚本实现的动态交互效果(设置首页)-----

Code:
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">   
  2. <html>   
  3.     <head>   
  4.         <title>setHome.html</title>   
  5.         <meta http-equiv="content-type" content="text/html; charset=UTF-8">   
  6.         <script language="JavaScript" type="text/javascript">   
  7.             function set()   
  8.             {   
  9.                 sethome.style.behavior="url(#default#homepage)";   
  10.                 sethome.setHomePage(http://www.google.com);   
  11.             }   
  12.         </script>   
  13.   
  14.     </head>   
  15.   
  16.     <body>   
  17.         <span id="sethome" οnclick="set()" style="CURSOR: hand"><br>将本站设置为首页</span>   
  18.     </body>   
  19. </html>  

//-----------进一步丰富鼠标的效果------------

Code:
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">   
  2. <html>   
  3.     <head>   
  4.         <title>movPic.html</title>   
  5.         <meta http-equiv="content-type" content="text/html; charset=UTF-8">   
  6.         <style type="text/css">   
  7.             <!--  
  8.             #topdown{   
  9.                 position:absolute;   
  10.                 left:12;   
  11.                 top:222;   
  12.                 }   
  13.             -->   
  14.         </style>   
  15.         <script language="JavaScript" type="text/javascript">   
  16.             function move(x, y)   
  17.             {   
  18.                 topdown.style.left = x;   
  19.                 topdown.style.top = y;   
  20.             }   
  21.         </script>   
  22.   
  23.     </head>   
  24.   
  25.     <body onmousemove="move(event.x, event.y)">    /×事件驱动×/
  26.         <div id="topdown">        /×id 样式修饰×/
  27.             <img src="smile.gif" alt="">    /*层标记 div×/
  28.         </div>   
  29.     </body>   
  30.   
  31. </html>  

 解释:使用层标记div将图片单独放在一层中,然后使用css层叠样式表定义了该图片的位置,再与onmouseover事件结合,追踪鼠标的位置(event.x 和event.y),并随时用鼠标的位置修改对应图片的位置。

 效果:页面中显示一张始终跟着鼠标指针移动的笑脸。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值