css minify/combine/param与PHP&Apache(对所有人都有用)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了css minify/combine/param与PHP&Apache(对所有人都有用)相关的知识,希望对你有一定的参考价值。

compress & combine CSS files and param theme with php vars
  1. /* in .htaccess */
  2. AddType application/x-httpd-php .css // to parse PHP var
  3.  
  4. /* on root CSS folder */
  5. <?php
  6. ob_start("ob_gzhandler");
  7. ob_start("compress");
  8. Header("Content-type:text/css;charset=utf-8");
  9. function compress($buffer) {
  10. // remove comments
  11. $buffer = preg_replace('!/*[^*]**+([^/][^*]**+)*/!', '', $buffer);
  12. // remove tabs, spaces, new lines
  13. $buffer = str_replace(array("
  14. ", " ", " ", " ", ' ', ' ', ' '), '', $buffer);
  15. // remove spaces
  16. $buffer = str_replace('{ ', '{', $buffer);
  17. $buffer = str_replace(' }', '}', $buffer);
  18. $buffer = str_replace('; ', ';', $buffer);
  19. $buffer = str_replace(', ', ',', $buffer);
  20. $buffer = str_replace(' {', '{', $buffer);
  21. $buffer = str_replace('} ', '}', $buffer);
  22. $buffer = str_replace(': ', ':', $buffer);
  23. $buffer = str_replace(' ,', ',', $buffer);
  24. $buffer = str_replace(' ;', ';', $buffer);
  25. return $buffer;
  26. }
  27.  
  28. // include your PHP vars
  29. include 'cssvar.php';
  30.  
  31. // and insert all your CSS files
  32. include 'reset.css';
  33. ?>
  34.  
  35.  
  36. /* in CSSVAR.PHP */
  37. <?php
  38. $v_css_gradient_blue = "
  39. background: #b8c1d7;
  40. background: -webkit-gradient(linear, left top, left bottom, from(#dae3ee), to(#b8c1d7));
  41. background: -moz-linear-gradient(top, #dae3ee, #b8c1d7);
  42. filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#dae3ee', endColorstr='#b8c1d7');
  43. ";
  44. ?>
  45.  
  46.  
  47. /* Use in CSS files */
  48. h1{
  49. padding:0 0 15px 0;
  50. margin:0;
  51. font-size:180%;
  52. <?php echo $v_css_gradient_blue;?>
  53. }

以上是关于css minify/combine/param与PHP&Apache(对所有人都有用)的主要内容,如果未能解决你的问题,请参考以下文章

CSS 过渡与 CSS 动画

css设置滚动条颜色与样式以及如何去掉与隐藏滚动条

css设置滚动条颜色与样式以及如何去掉与隐藏滚动条

css 重力形式CSS与隐藏标签

css 脉冲动画与CSS

css 纹理背景,与浮动-text.css