青海文学期刊投稿:CSS实例(六):实现网页固定大小三态图形按钮简单方法

来源:百度文库 编辑:九乡新闻网 时间:2024/04/27 16:05:34
今天想出一种三态图形按钮实现方式,制作超简单,文字可以随意修改,各种浏览器表现一致,不含任何JS脚本。

  需要一个图片文件:




  网页代码:
Html代码  
  1.   
  2.   
  3.   
  4.   
  5.   
  6. first page  
  7.   
  8. /*  
  9. bib:big image button  
  10. sib:small image button  
  11. lib:long image button  
  12. lsib:long button with search image  
  13. by wallimn, http://wallimn.iteye.com  
  14. */  
  15. .bib,.sib,.lib,.lsib{  
  16.     border-width:0;  
  17.     vertical-align:middle;  
  18.     background-color:transparent;  
  19.     margin:0;  
  20.     overflow:visible;  
  21.     background-repeat:no-repeat;  
  22.     background-image:url(buttons.gif) ;   
  23. }  
  24. .bib{  
  25.     width:93px;  
  26.     height:30px;  
  27.     line-height:30px;  
  28.     background-position: 0 -132px;  
  29. }  
  30. .bib:hover{  
  31.     background-position:0 -162px;  
  32. }  
  33. .sib{  
  34.     width:44px;  
  35.     height:22px;  
  36.     line-height:22px;  
  37.     background-position: 0 0;  
  38. }  
  39. .sib:hover{  
  40.     background-position:0 -22px;  
  41. }  
  42. .lib{  
  43.     width:66px;  
  44.     height:22px;  
  45.     line-height:22px;  
  46.     background-position: 0 -44px;  
  47. }  
  48. .lib:hover{  
  49.     background-position:0 -66px;  
  50. }  
  51. .lsib{  
  52.     width:66px;  
  53.     height:22px;  
  54.     line-height:22px;  
  55.     background-position: 0 -88px;  
  56. }  
  57. .lsib:hover{  
  58.     background-position:0 -110px;  
  59. }  
  60. /*end of button style*/  
  61.   
  62.   
  63.   
  64.       
  65.       
  66.       
  67.       
  68.   
  69.   
  70.   


   最终效果:




  有个限制,按钮的大小固定成几种尺寸模式,一般来讲,网页上的图形按钮应该也就几种大小,不会有各种各样大小的按钮。固定按钮大小,可以获得非常简洁的代码。

  IE6不支持hover伪类,很让人郁闷。不过不影响外观。