教学之友,学习之友。

站长教学网

当前位置: 站长教学网 > 前端开发 > CSS教程 >

你应该知道的30个实用CSS代码(6)

时间:2012-03-25 20:25来源:未知 作者:ken 点击:

24. Browser CSS hacks

大量的CSS hack帮助你让你的网站在所有浏览器下显示一致

  1. /***** Selector Hacks ******/ 
  2.  
  3. /* IE6 and below */ 
  4. * html #uno  { colorred }  
  5.  
  6. /* IE7 */ 
  7. *:first-child+html #dos { colorred }   
  8.  
  9. /* IE7, FF, Saf, Opera  */ 
  10. html>body #tres { colorred }  
  11.  
  12. /* IE8, FF, Saf, Opera (Everything but IE 6,7) */ 
  13. html>/**/body #cuatro { colorred }  
  14.  
  15. /* Opera 9.27 and below, safari 2 */ 
  16. html:first-child #cinco { colorred }  
  17.  
  18. /* Safari 2-3 */ 
  19. html[xmlns*=""] body:last-child #seis { colorred }  
  20.  
  21. /* safari 3+, chrome 1+, opera9+, ff 3.5+ */ 
  22. body:nth-of-type(1#siete { colorred }  
  23.  
  24. /* safari 3+, chrome 1+, opera9+, ff 3.5+ */ 
  25. body:first-of-type #ocho {  colorred }  
  26.  
  27. /* saf3+, chrome1+ */ 
  28. @media screen and (-webkit-min-device-pixel-ratio:0) {  
  29.  #diez  { colorred  }  
  30. }  
  31.  
  32. /* iPhone / mobile webkit */ 
  33. @media screen and (max-device-width480px) {  
  34.  #veintiseis { colorred  }  
  35. }  
  36.  
  37. /* Safari 2 - 3.1 */ 
  38. html[xmlns*=""]:root #trece  { colorred  }  
  39.  
  40. /* Safari 2 - 3.1, Opera 9.25 */ 
  41. *|html[xmlns*=""#catorce { colorred  }  
  42.  
  43. /* Everything but IE6-8 */ 
  44. :root *> #quince { colorred  }  
  45.  
  46. /* IE7 */ 
  47. *+html #dieciocho {  colorred }  
  48.  
  49. /* Firefox only. 1+ */ 
  50. #veinticuatro,  x:-moz-any-link  { colorred }  
  51.  
  52. /* Firefox 3.0+ */ 
  53. #veinticinco,  x:-moz-any-link, x:default  { colorred  }  
  54.  
  55. /* FF 3.5+ */ 
  56. body:not(:-moz-handler-blocked) #cuarenta { colorred; }  
  57.  
  58. /***** Attribute Hacks ******/ 
  59.  
  60. /* IE6 */ 
  61. #once { _colorblue }  
  62.  
  63. /* IE6, IE7 */ 
  64. #doce { *colorblue/* or #color: blue */ }  
  65.  
  66. /* Everything but IE6 */ 
  67. #diecisiete { color/**/blue }  
  68.  
  69. /* IE6, IE7, IE8 */ 
  70. #diecinueve { colorblue\9; }  
  71.  
  72. /* IE7, IE8 */ 
  73. #veinte { color/*\**/blue\9; }  
  74.  
  75. /* IE6, IE7 -- acts as an !important */ 
  76. #veintesiete { colorblue !ie; } /* string after ! can be anything */ 
  77.  
  78. /* IE8, IE9 */ 
  79. #anotherone  {colorblue\0/;} /* must go at the END of all rules */ 

25. How To Change The Default Text Selection Color on your Blog

修改高亮的文字颜色

  1. ::selection {  
  2.    background#ffb7b7/* Safari */ 
  3.         color#ffffff;  
  4.    }  
  5. ::-moz-selection {  
  6.    background#ffb7b7/* Firefox */ 
  7.         color#ffffff;  
  8.    } 

26. Clearfix

  1. .clearfix:after {  
  2.     visibilityhidden;  
  3.     displayblock;  
  4.     font-size0;  
  5.     content" ";  
  6.     clearboth;  
  7.     height0;  
  8. }  
  9.  
  10. .clearfix { display: inline-block; }  
  11.  
  12. /* start commented backslash hack \*/ 
  13. * html .clearfix { height1%; }  
  14. .clearfix { displayblock; }  
  15. /* close commented backslash hack */ 

27. Hide Logo Text With Text Indent

使得你的logo SEO友好。保证logo文字不显示

  1. h1 {  
  2.         text-indent:-9999px;  
  3.         margin:0 auto;  
  4.         width:400px;  
  5.         height:100px;  
  6.         background:transparent url("images/logo.jpg"no-repeat scroll;  

28. Reset all Text Colors and Background Colors

重置所有的背景和文字颜色。

  1. * {  
  2.      colorblack !important;  
  3.      background-colorwhite !important;  
  4.      background-imagenone !important;  

29. Multiple Background Images

使用多背景图片

  1. #multiple-images {  
  2.    backgroundurl(image_1.png) top left no-repeat,  
  3.    url(image_2.png) bottom left no-repeat,  
  4.    url(image_3.png) bottom right no-repeat;  

30. Linear Gradient

允许你为背景创建一个线状渐变效果,不支持一些老浏览器

  1. background: -webkit-gradient(linear, left topleft bottom, from(#74b8d7), to(#437fbc));  
  2. background: -moz-linear-gradient(top,  #74b8d7,  #437fbc);  
  3. filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#74b8d7', endColorstr='#437fbc'); 
(责任编辑:ken)
TAG标签:
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
注册登录:不允许匿名留言,登录后留言无需输入验证码。
栏目列表
最新内容