<!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>
时间: 2024-10-12 05:45:33