CSS的一些实用例子

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

Code:
  1. <!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
  2. <html>
  3. <head>
  4. <title>css11.html</title>
  5. <metahttp-equiv="content-type"content="text/html;charset=UTF-8">
  6. <styletype="text/css">
  7. <!--
  8. div.show{
  9. position:absolute;
  10. top:10;
  11. left:200;
  12. visibility:visible;
  13. }
  14. div.hide{
  15. position:absolute;
  16. top:120;
  17. left:200;
  18. visibility:hidden;
  19. }
  20. -->
  21. </style>
  22. </head>
  23. <body>
  24. <divclass="hide"> //将不显示
  25. <imgsrc="smile.gif"alt="">
  26. </div>
  27. <divclass="show">
  28. <imgsrc="cry.gif"alt="">
  29. </div>
  30. </body>
  31. </html>

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

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

Code:
  1. <!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
  2. <html>
  3. <head>
  4. <title>css12.html</title>
  5. <metahttp-equiv="content-type"content="text/html;charset=UTF-8">
  6. <styletype="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. </head>
  24. <body>
  25. <pclass="hand">
  26. Givemeahand!(手形)
  27. </p>
  28. <pclass="crosshair">
  29. Givemeacrosshair(精确定位)!
  30. </p>
  31. <pclass="move">
  32. GivemeaMove(移动)!
  33. </p>
  34. <pclass="e-resize">
  35. Givemeae-resize(箭头方向朝右)!
  36. </p>
  37. <pclass="ne-resize">
  38. Givemeane-resize(箭头方向朝右上)!
  39. </p>
  40. <pclass="nw-resize">
  41. Givemeanw-resize(箭头方向朝左上)!
  42. </p>
  43. <pclass="n-resize">
  44. Givemean-resize(上)!
  45. </p>
  46. <pclass="se-resize">
  47. Givemease-resize(左下)!
  48. </p>
  49. <pclass="s-resize">
  50. Givemeas-resize(下)!
  51. </p>
  52. <pclass="w-resize">
  53. Givemeaw-resize(左)!
  54. </p>
  55. <pclass="text">
  56. Givemeatext(文本)!
  57. </p>
  58. <pclass="wait">
  59. Givemeawait(等待)!
  60. </p>
  61. <pclass="help">
  62. Givemeahelp(帮助)!
  63. </p>
  64. </body>
  65. </html>

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

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

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

Code:
  1. <!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
  2. <html>
  3. <head>
  4. <title>movPic.html</title>
  5. <metahttp-equiv="content-type"content="text/html;charset=UTF-8">
  6. <styletype="text/css">
  7. <!--
  8. #topdown{
  9. position:absolute;
  10. left:12;
  11. top:222;
  12. }
  13. -->
  14. </style>
  15. <scriptlanguage="JavaScript"type="text/javascript">
  16. functionmove(x,y)
  17. {
  18. topdown.style.left=x;
  19. topdown.style.top=y;
  20. }
  21. </script>
  22. </head>
  23. <bodyonmousemove="move(event.x,event.y)"> /×事件驱动×/
  24. <divid="topdown"> /×id 样式修饰×/
  25. <imgsrc="smile.gif"alt=""> /*层标记 div×/
  26. </div>
  27. </body>
  28. </html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值