日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
使用lesscss來編碼編寫CSS

lesscss 是動態(tài)的樣式表語言,他讓css增加變量,組合,函數(shù),運算等語法。這個項目的網(wǎng)站在國內(nèi)訪問不到,大家都懂的。這里只給出地址:http://www.lesscss.org/

lesscss使用方法有兩種:

◆ 頁面添加一個 less.js的文件,css使用 style.less 文件后綴來編寫,不過需要有服務(wù)器的環(huán)境支持

 
 
 
 
  1.  
  2.  

◆ 在服務(wù)器端使用node.js來編譯,node.js 使用 less的方法如下:

先使用npm包管理器來安裝

$ npm install less

然后就可以使用命令行來編譯壓縮less代碼了

$ lessc styles.less > styles.css

下面是一些lesscss的語法:

使用變量

 
 
 
 
  1. // LESS   
  2. @color: #4D926F;     
  3. #header {  
  4.   color: @color;  
  5. }  
  6. h2 {  
  7.   color: @color;  
  8. }  
  9. /* Compiled CSS */    
  10. #header {  
  11.   color: #4D926F;  
  12. }  
  13. h2 {  
  14.   color: #4D926F;  
  15. }  

2.組合

 
 
 
 
  1. // LESS  
  2.    
  3. .rounded-corners (@radius: 5px) {  
  4.   border-radius: @radius;  
  5.   -webkit-border-radius: @radius;  
  6.   -moz-border-radius: @radius;  
  7. }  
  8.    
  9. #header {  
  10.   .rounded-corners;  
  11. }  
  12. #footer {  
  13.   .rounded-corners(10px);  
  14. }  
  15. /* Compiled CSS */ 
  16.    
  17. #header {  
  18.   border-radius: 5px;  
  19.   -webkit-border-radius: 5px;  
  20.   -moz-border-radius: 5px;  
  21. }  
  22. #footer {  
  23.   border-radius: 10px;  
  24.   -webkit-border-radius: 10px;  
  25.   -moz-border-radius: 10px;  
  26. }  

3.選擇器

 
 
 
 
  1. // LESS  
  2.    
  3. #header {  
  4.   h1 {  
  5.     font-size: 26px;  
  6.     font-weight: bold;  
  7.   }  
  8.   p { font-size: 12px;  
  9.     a { text-decoration: none;  
  10.       &:hover { border-width: 1px }  
  11.     }  
  12.   }  
  13. }  
  14.    
  15. /* Compiled CSS */ 
  16.    
  17. #header h1 {  
  18.   font-size: 26px;  
  19.   font-weight: bold;  
  20. }  
  21. #header p {  
  22.   font-size: 12px;  
  23. }  
  24. #header p a {  
  25.   text-decoration: none;  
  26. }  
  27. #header p a:hover {  
  28.   border-width: 1px;  
  29. }  

4. 變量預(yù)算

 
 
 
 
  1. // LESS  
  2.    
  3. @the-border: 1px;  
  4. @base-color: #111;  
  5. @red:        #842210;  
  6.    
  7. #header {  
  8.   color: @base-color * 3;  
  9.   border-left: @the-border;  
  10.   border-right: @the-border * 2;  
  11. }  
  12. #footer {  
  13.   color: @base-color + #003300;  
  14.   border-color: desaturate(@red, 10%);  
  15. }  
  16.    
  17. /* Compiled CSS */ 
  18.    
  19. #header {  
  20.   color: #333;  
  21.   border-left: 1px;  
  22.   border-right: 2px;  
  23. }  
  24. #footer {  
  25.   color: #114411;  
  26.   border-color: #7d2717;  
  27. }  

5. import 外部css

 
 
 
 
  1. @import "lib.less";  
  2. @import "lib";  

通用引用了lesscss,我們就可以將css寫得模塊化,有更好的閱讀性。

首先可以通過 import 講網(wǎng)站的樣式分成 n個模塊,當(dāng)頁面需要哪個模塊就引用哪個。還可以將css3那些新增的功能定義成類庫,由于有函數(shù)的功能,那些圓角,陰影之類樣式只需要定義一次就可以了。講頁面需要使用到的主要文本,邊框,背景色定義成變量給后續(xù)樣式使用,到時網(wǎng)站風(fēng)格需要改變,顏色也很好的修改。

我個人覺得先階段lesscss的不足有:

1. css3的樣式不能自動補全其他瀏覽器的hack。

2.使用nodejs在window系統(tǒng)下的支持不夠,不過最近剛剛不久發(fā)布了一個nodejs window版,這方面估計在不久的將來會改善

3.編輯器,ide對lesscss語法縮進(jìn)支持不夠友好。

原文:http://www.cnblogs.com/qiangji/archive/2011/08/01/lesscss.html


網(wǎng)站名稱:使用lesscss來編碼編寫CSS
分享地址:http://www.dlmjj.cn/article/copcsdd.html