自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

使用lesscss來編碼編寫CSS

開發(fā) 前端
lesscss 是動態(tài)的樣式表語言,他讓css增加變量,組合,函數(shù),運算等語法。

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

 

lesscss使用方法有兩種:

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

  1. <link rel="stylesheet/less" type="text/css" href="styles.less">  
  2. <script src="less.js" type="text/javascript"></script>  

◆ 在服務器端使用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-size26px;  
  6.     font-weightbold;  
  7.   }  
  8.   p { font-size12px;  
  9.     a { text-decorationnone;  
  10.       &:hover { border-width1px }  
  11.     }  
  12.   }  
  13. }  
  14.    
  15. /* Compiled CSS */ 
  16.    
  17. #header h1 {  
  18.   font-size26px;  
  19.   font-weightbold;  
  20. }  
  21. #header p {  
  22.   font-size12px;  
  23. }  
  24. #header p a {  
  25.   text-decorationnone;  
  26. }  
  27. #header p a:hover {  
  28.   border-width1px;  
  29. }  

4. 變量預算

  1. // LESS  
  2.    
  3. @the-border1px;  
  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(@red10%);  
  15. }  
  16.    
  17. /* Compiled CSS */ 
  18.    
  19. #header {  
  20.   color#333;  
  21.   border-left1px;  
  22.   border-right2px;  
  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個模塊,當頁面需要哪個模塊就引用哪個。還可以將css3那些新增的功能定義成類庫,由于有函數(shù)的功能,那些圓角,陰影之類樣式只需要定義一次就可以了。講頁面需要使用到的主要文本,邊框,背景色定義成變量給后續(xù)樣式使用,到時網(wǎng)站風格需要改變,顏色也很好的修改。

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

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

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

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

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

【編輯推薦】

  1. 8月8款非常實用的CSS工具推薦
  2. HTML 5和CSS3表單示例和詳細教程匯總
  3. Web設計師必備:10款***免費CSS在線編輯器
  4. 44個驚人的超炫CSS3動畫演示
  5. 六月***的HTML 5和CSS3教程強烈推薦
責任編輯:陳貽新 來源: 強記的博客
相關推薦

2010-09-13 10:00:51

CSS注釋

2010-09-06 09:06:22

CSS

2020-03-26 10:43:57

CSS Grid Ge Grid代碼

2023-10-30 09:18:28

CSSColumns布局

2013-04-08 12:41:35

JavaScriptJS

2010-08-31 13:32:12

CSS

2010-09-13 10:11:06

CSSDWMX

2010-09-10 15:23:54

CSS匹配CSS

2024-05-11 18:48:40

技巧代碼技能

2010-09-03 09:14:28

CSS

2010-09-09 11:16:06

CSS交互

2013-03-11 10:30:56

CSSWeb

2010-09-07 13:04:14

CSS Hack

2010-08-26 15:27:57

CSS

2017-08-28 14:58:19

CSSFlexbox注釋格式優(yōu)化

2016-09-07 19:58:47

CSS代碼Web

2024-05-13 11:36:23

CSS文本屬性

2011-01-11 13:40:44

webcssdiv

2010-08-27 09:37:44

DIV CSS

2024-01-22 10:31:09

Kate文檔
點贊
收藏

51CTO技術棧公眾號