码迷,mamicode.com
首页 > Web开发 > 详细

CSS格式化 CSS代码压缩工具

时间:2014-11-29 17:33:50      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   使用   sp   java   

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>CSS格式化 css代码在线压缩-CSS代码格式化,css在线压缩工具可减少CSS文件体积,让CSS文件更规范</title>
<style> 
body,textarea,input{font:11pt "微软雅黑",Tahoma;}
</style>
<meta http-equiv="x-ua-compatible" content="ie=7" /> 
 <script language=JavaScript> 
<!-- 
function $() { 
  var elements = new Array(); 
  for (var i = 0; i < arguments.length; i++) { 
  var element = arguments[i]; 
  if (typeof element == string) 
    element = document.getElementById(element); 
  if (arguments.length == 1)  
    return element;    
  elements.push(element); 
  }    
  return elements; 
} 
function CSSencode(code) 
{ 
 code = code.replace(/\n/ig,‘‘); 
 code = code.replace(/(\s){2,}/ig,$1); 
 code = code.replace(/\t/ig,‘‘); 
 code = code.replace(/\n\}/ig,\}); 
 code = code.replace(/\n\{\s*/ig,\{); 
 code = code.replace(/(\S)\s*\}/ig,$1\}); 
 code = code.replace(/(\S)\s*\{/ig,$1\{); 
 code = code.replace(/\{\s*(\S)/ig,\{$1); 
 return code; 
} 
function CSSdecode(code) 
{ 
 code = code.replace(/(\s){2,}/ig,$1); 
 code = code.replace(/(\S)\s*\{/ig,$1 {); 
 code = code.replace(/\*\/(.[^\}\{]*)}/ig,\*\/\n$1}); 
 code = code.replace(/\/\*/ig,\n\/\*); 
 code = code.replace(/;\s*(\S)/ig,;\n\t$1); 
 code = code.replace(/\}\s*(\S)/ig,\}\n$1); 
 code = code.replace(/\n\s*\}/ig,\n\}); 
 code = code.replace(/\{\s*(\S)/ig,\{\n\t$1); 
 code = code.replace(/(\S)\s*\*\//ig,$1\*\/); 
 code = code.replace(/\*\/\s*([^\}\{]\S)/ig,\*\/\n\t$1); 
 code = code.replace(/(\S)\}/ig,$1\n\}); 
 code = code.replace(/(\n){2,}/ig,\n); 
 code = code.replace(/:/ig,: ); 
 code = code.replace(/  /ig,‘ ‘); 
 return code; 
} 
//--> 
</script>
</head>
<body>
<table width="80%" border="0" cellspacing="3" cellpadding="0" align="center">
    <tr>
      <td>CSS代码在线压缩工具,CSS格式化,让CSS代码更规范,体积更小,有利于阅读代码和网页加载速度。而且本页提供的CSS代码格式化功能不需要使用YUI Compressor 或者 CSSTidy等离线工具,直接在线操作。</td>
    </tr>
    <tr>
      <td><textarea id=code title="请把CSS代码粘贴在这里" style="WIDTH: 100%; HEIGHT: 300px"></textarea></td>
    </tr>
    <tr>
      <td><input onClick="$(‘code‘).value = CSSdecode($(‘code‘).value);" type=button value=格式化>  <input onClick="$(‘code‘).value = CSSencode($(‘code‘).value);" type=button value=压缩化>  <input onClick="window.clipboardData.setData(‘Text‘,$(‘code‘).value);" type=button value=复制>  <input onClick="$(‘code‘).value = window.clipboardData.getData(‘Text‘);" type=button value=粘贴>  <input onClick="$(‘code‘).value = ‘‘" type=button value=清空> </td>
    </tr>
  </table>
</body>
</html>

 

CSS格式化 CSS代码压缩工具

标签:style   blog   http   io   ar   color   使用   sp   java   

原文地址:http://www.cnblogs.com/hellowzd/p/4131180.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!