CSS代码格式化


 浏览器运行效果图:

成品预览图:

成品windows程序下载:打包成EXE文件了,可以在win平台直接运行。地址:http://pan.baidu.com/s/1c0c4FdA

将下面代码框内的所有代码复制到系统记事本里,另存为html格式的网页文件,之后用浏览器打开即可

工具源代码:

<style>textarea{width:100%;height:80%;}</style>
<div class="toolcode">
<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(/\r\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>
        <h3>CSS代码格式化</h3>
        <textarea class="toolarea" id=code name="textarea">
#input.button {
    height: 20px;
    line-height: 18px;
    padding: 0px 5px 0px;
    background-color: white;
    border: 1px solid #ccc;
    cursor: pointer;
}
#input.button-submit {
    height: 20px;
    line-height: 18px;
    padding: 0px 5px 0px;
    background-color: white;
    border: 1px solid #ccc;
    cursor: pointer;
    color: red;
}
/****** Info Box Styles ******/
    .infoBox {
    border:1px solid #ccc;
    padding:5px;
    margin:0px;
    background-color: #ffffe1;
    color: #333;
}
/* a style which makes div touch the bottom of content*/
    .clear {
    border-top:1px solid transparent !important;
    margin-top:-1px !important;
    border-top:0;
    margin-top:0;
    clear:both;
    visibility:hidden;
}
</textarea>
        <hr><input class="bt-green" onclick="$('code').value = CSSencode($('code').value);" value=横排格式化 type=button> <input class="bt-blue" onclick="$('code').value = CSSdecode($('code').value);" value=竖排格式化 type=button>
</div>

 

转载于:https://www.cnblogs.com/buzhaoshi/p/4854436.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值