欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

CSS的預(yù)處理框架stylus是怎樣的

CSS的預(yù)處理框架stylus是怎樣的,相信很多沒(méi)有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。

成都創(chuàng)新互聯(lián)公司專注于企業(yè)成都全網(wǎng)營(yíng)銷、網(wǎng)站重做改版、塔什庫(kù)爾干塔吉克網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、html5、商城網(wǎng)站開(kāi)發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為塔什庫(kù)爾干塔吉克等各大城市提供網(wǎng)站開(kāi)發(fā)制作服務(wù)。

stylus介紹

是個(gè)什么鬼?對(duì)于開(kāi)發(fā)來(lái)說(shuō),CSS的弱點(diǎn)在于靜態(tài)化。我們需要一個(gè)真正能提高開(kāi)發(fā)效率的工具,LESS, SASS都在這方面做了一些貢獻(xiàn)。

Stylus 是一個(gè)CSS的預(yù)處理框架,2010年產(chǎn)生,來(lái)自Node.js社區(qū),主要用來(lái)給Node項(xiàng)目進(jìn)行CSS預(yù)處理支持,所以 Stylus 是一種新型語(yǔ)言,可以創(chuàng)建健壯的、動(dòng)態(tài)的、富有表現(xiàn)力的CSS。比較年輕,其本質(zhì)上做的事情與 SASS/LESS 等類似,應(yīng)該是有很多借鑒,所以近似腳本的方式去寫CSS代碼。

Stylus默認(rèn)使用 .styl 的作為文件擴(kuò)展名,支持多樣性的CSS語(yǔ)法。

Stylus功能上更為強(qiáng)壯,和js聯(lián)系更加緊密。所以我選擇 Stylus,SASS 玩兒過(guò)一段時(shí)間,主要是這玩意依賴ruby運(yùn)行,所以我放棄使用了。
Stylus安裝

全局安裝,安裝之前你需要你安裝 nodejs 這個(gè)怎么安裝搜去哦。

代碼如下:

$ npm install stylus -g

這樣就算是安裝完Stylus了,也可以正常使用Stylus。

代碼如下:

Usage: stylus [options] [command] [< in [> out]]
             [file|dir ...]
Commands:
 help <prop>     Opens help info for <prop> in
                 your default browser. (OS X only)
Options:</p> <p>  -u, --use <path>        Utilize the stylus plugin at <path>
 -i, --interactive       Start interactive REPL
 -w, --watch             Watch file(s) for changes and re-compile
 -o, --out <dir>         Output to <dir> when passing files
 -C, --css <src> [dest]  Convert CSS input to Stylus
 -I, --include <path>    Add <path> to lookup paths
 -c, --compress          Compress CSS output
 -d, --compare           Display input along with output
 -f, --firebug           Emits debug infos in the generated css that
                         can be used by the FireStylus Firebug plugin
 -l, --line-numbers      Emits comments in the generated CSS
                         indicating the corresponding Stylus line
 -V, --version           Display the version of Stylus
 -h, --help              Display help information

生成CSS
命令行中

建立一個(gè)stylusExample/,再在里面建立 src 目錄專門存放 stylus 文件,在里面建立 example.styl 文件。然后在 stylusExample 目錄下面執(zhí)行下面命令

代碼如下:

$ stylus --compress src/

輸出compiled src/example.css ,這個(gè)時(shí)候表示你生成成功了,帶上--compress參數(shù)表示你生成壓縮的CSS文件。

$ stylus --css css/example.css css/out.styl CSS轉(zhuǎn)換成styl
$ stylus help box-shadow CSS屬性的幫助
$ stylus --css test.css 輸出基本名一致的.styl文件
grunt生成

grunt生成 就比較爽歪歪了,具體grunt怎么玩兒,俺寫了個(gè)教程Grunt教程-前端自動(dòng)化 可以學(xué)習(xí)以下。

stylusExample 目錄下創(chuàng)建兩個(gè)文件,這兩個(gè)文件是grunt必備文件。

    package.json:用于保存項(xiàng)目元數(shù)據(jù)。
    Gruntfile.js:用于配置或定義任務(wù)、加載 Grunt 插件。

package.json 內(nèi)容

JavaScript

  1. {   

  2.   "name": "test",   

  3.   "version": "1.0.0",   

  4.   "description": "測(cè)試的例子",   

  5.   "repository": {   

  6.     "type": "git",   

  7.     "url": ""  

  8.   }   

  9. }  

然后安裝必備插件,這些插件讓stylus文件變更了自動(dòng)生成,生成到相對(duì)應(yīng)的文件目錄中。如果報(bào)錯(cuò)你需要在命令行前面加上sudo,給它最大的執(zhí)行權(quán)限。

npm install grunt --save-dev
npm install grunt-contrib-watch --save-dev :監(jiān)視文件變動(dòng),做出相應(yīng)動(dòng)作。npm>>
npm install grunt-contrib-stylus --save-dev :stylus編寫styl輸出css npm>>

安裝出現(xiàn)這樣的警告 npm WARN package.json test@1.0.0 No README data 可以不理會(huì),如果你看著不舒服,你需要在stylusExample目錄下面建立一個(gè) README.md 文件并輸入內(nèi)容。也可命令執(zhí)行 echo "#stylus 學(xué)習(xí)" >> README.md

插件執(zhí)行完畢之后 package.json 文件變成了這樣樣子滴。

JavaScript 

  1. {   

  2.   "name": "test",   

  3.   "version": "1.0.0",   

  4.   "description": "測(cè)試的例子",   

  5.   "repository": {   

  6.     "type": "git",   

  7.     "url": ""  

  8.   },   

  9.   "devDependencies": {   

  10.     "grunt": "^0.4.5",   

  11.     "grunt-contrib-stylus": "^0.21.0",   

  12.     "grunt-contrib-watch": "^0.6.1"  

  13.   }   

  14. }  

這個(gè)時(shí)候你需要使用這些插件兒完成你的任務(wù)需要在Gruntfile.js里面寫你的執(zhí)行任務(wù)。

JavaScript 

  1. /// 包裝函數(shù)  

  2. module.exports = function(grunt) {   

  3.     // 任務(wù)配置,所有插件的配置信息  

  4.     grunt.initConfig({   

  5.         pkg: grunt.file.readJSON('package.json'),   

  6.         stylus:{   

  7.             build: {   

  8.                 options: {   

  9.                     linenos: false,   

  10.                     compress: true  

  11.                 },   

  12.                 files: [{   

  13.                     'css/index.css': ['src/index.styl']   

  14.                 }]   

  15.             }   

  16.         },   

  17.         // watch插件的配置信息  

  18.         watch: {   

  19.             another: {   

  20.                 files: ['css/*','src/*.styl'],   

  21.                 tasks: ['stylus'],   

  22.                 options: {   

  23.                     livereload: 1337   

  24.                 }   

  25.             }   

  26.         }   

  27.     });   

  28.     // 告訴grunt我們將使用插件  

  29.     grunt.loadNpmTasks('grunt-contrib-watch');   

  30.     grunt.loadNpmTasks('grunt-contrib-stylus');   

  31.     // 告訴grunt當(dāng)我們?cè)诮K端中輸入grunt時(shí)需要做些什么  

  32.     grunt.registerTask('default', ['watch']);   

  33. };  

注意讀懂上面的哦,目錄高對(duì)哦,這些沒(méi)有必要提醒哦,這個(gè)時(shí)候你可以好好耍一下stylus
Stylus應(yīng)用

這個(gè)時(shí)候真正的開(kāi)始玩耍了哦。
Try Stylus!

stylus

CSS

  1. body,html   

  2.     margin:0   

  3.     padding:0  

編譯成

CSS

  1. body,   

  2. html {   

  3.   margin: 0;   

  4.   padding: 0;   

  5. }  

stylus : 強(qiáng)大的功能豐富的語(yǔ)言

CSS

  1. -pos(type, args)   

  2.   i = 0   

  3.   position: unquote(type)   

  4.   {args[i]}: args[i + 1] is a 'unit' ? args[i += 1] : 0   

  5.   {args[i += 1]}: args[i + 1] is a 'unit' ? args[i += 1] : 0   

  6.   

  7. absolute()   

  8.   -pos('absolute', arguments)   

  9.   

  10. fixed()   

  11.   -pos('fixed', arguments)   

  12.   

  13. #prompt  

  14.   absolute: top 150px left 5px  

  15.   width: 200px  

  16.   margin-left: -(@width / 2)   

  17.   

  18. #logo  

  19.   fixed: top left  

編譯成

CSS 

  1. #prompt {   

  2.   position: absolute;   

  3.   top: 150px;   

  4.   left: 5px;   

  5.   width: 200px;   

  6.   margin-left: -100px;   

  7. }   

  8. #logo {   

  9.   position: fixed;   

  10.   top: 0;   

  11.   left: 0;   

  12. }  

nibStylus插件

stylus

CSS

  1. @import 'nib'  

  2. body   

  3.   background: linear-gradient(20px top, white, black)   

編譯成

CSS 

  1. body {   

  2.   background: -webkit-linear-gradient(20px top, #fff, #000);   

  3.   background: -moz-linear-gradient(20px top, #fff, #000);   

  4.   background: -o-linear-gradient(20px top, #fff, #000);   

  5.   background: -ms-linear-gradient(20px top, #fff, #000);   

  6.   background: linear-gradient(20px top, #fff, #000);   

  7. }  

Nesting(嵌套)

stylus

CSS

  1. header   

  2.     #logo  

  3.         border:1px solid red  

編譯成

header #logo {
  border: 1px solid #f00;
}

Flexible syntax(靈活的用法)

stylus

CSS

  1. body   

  2.     font 14px/1.5 Helvetica, arial, sans-serif  

  3.     button   

  4.     button.button   

  5.     input[type='button']   

  6.     input[type='submit']   

  7.         border-radius 5px  

  8.   

  9. header    

  10.     #logo,div   

  11.         font-size:14px  

編譯成

CSS

  1. body {   

  2.   font: 14px/1.5 Helvetica, arial, sans-serif;   

  3. }   

  4. body button,   

  5. body button.button,   

  6. body input[type='button'] {   

  7.   border-radius: 5px;   

  8. }   

  9. header #logo,   

  10. header div {   

  11.   font-size: 14px;   

  12. }  

Flexible &(靈活&)

stylus

CSS 

  1. ul   

  2.     li a   

  3.         display: block  

  4.         color: blue  

  5.         padding: 5px  

  6.         html.ie &   

  7.             padding: 6px  

  8.         &:hover   

  9.             color: red  

編譯成

CSS

  1. ul li a {   

  2.   display: block;   

  3.   color: #00f;   

  4.   padding: 5px;   

  5. }   

  6. html.ie ul li a {   

  7.   padding: 6px;   

  8. }   

  9. ul li a:hover {   

  10.   color: #f00;   

  11. }  

Functions 方法
返回值

stylus

CSS 

  1. border-radius(val)   

  2.     -webkit-border-radius: val   

  3.     -moz-border-radius: val   

  4.     border-radius: val   

  5.   

  6. button    

  7.     border-radius(5px);  

編譯成

CSS

  1. button {   

  2.   -webkit-border-radius: 5px;   

  3.   -moz-border-radius: 5px;   

  4.   border-radius: 5px;   

  5. }  

Transparent mixins

不帶參數(shù)

stylus

CSS 

  1. border-radius()   

  2.     -webkit-border-radius: arguments   

  3.     -moz-border-radius: arguments   

  4.     border-radius: arguments   

  5.   

  6. button    

  7.     border-radius: 5px 10px;  

編譯成

CSS 

  1. button {   

  2.   -webkit-border-radius: 5px 10px;   

  3.   -moz-border-radius: 5px 10px;   

  4.   border-radius: 5px 10px;   

  5. }  

默認(rèn)參數(shù)

不帶參數(shù)

stylus

CSS 

  1. add(a, b = a)   

  2.   a + b   

  3.   

  4. add(10, 5)   

  5. // => 15   

  6.   

  7. add(10)   

  8. // => 20  

函數(shù)體

通過(guò)內(nèi)置unit()把單位都變成px, 因?yàn)橘x值在每個(gè)參數(shù)上,因此,我們可以無(wú)視單位換算。

CSS Code復(fù)制內(nèi)容到剪貼板

  1. add(a, b = a)   

  2.   a = unit(a, px)   

  3.   b = unit(b, px)   

  4.   a + b   

  5.   

  6. add(15%, 10deg)   

  7. // => 25  

多個(gè)返回值

通過(guò)內(nèi)置unit()把單位都變成px, 因?yàn)橘x值在每個(gè)參數(shù)上,因此,我們可以無(wú)視單位換算。

CSS 

  1. sizes()   

  2.  15px 10px  

  3.   

  4. sizes()[0]   

  5. // => 15px  

Variables(變量)
常用方法

CSS

  1. stylus   

  2.   

  3. font-size = 14px  

  4.   

  5. body   

  6.     font font-size Arial, sans-seri  

編譯成

CSS 

  1. body {   

  2.   font: 14px Arial, sans-seri;   

  3. }  

變量放在屬性中

stylus

CSS 

  1. #prompt  

  2.     position: absolute  

  3.     top: 150px  

  4.     left: 50%   

  5.     width: w = 200px  

  6.     margin-left: -(w / 2)  

編譯成

CSS 

  1. #prompt {   

  2.   position: absolute;   

  3.   top: 150px;   

  4.   left: 50%;   

  5.   width: 200px;   

  6.   margin-left: -100px;   

  7. }  

塊屬性訪問(wèn)引用

stylus

CSS 

  1. #prompt  

  2.     position: absolute  

  3.     width: 200px  

  4.     margin-left: -(@width / 2)  

編譯成

CSS 

  1. #prompt {   

  2.   position: absolute;   

  3.   width: 200px;   

  4.   margin-left: -100px;   

  5. }  

屬性有條件地定義屬性

stylus:指定z-index值為1,但是,只有在z-index之前未指定的時(shí)候才這樣:

CSS

  1. position()   

  2.   position: arguments   

  3.   z-index: 1 unless @z-index  

  4.   

  5. #logo  

  6.   z-index: 20   

  7.   position: absolute  

  8.   

  9. #logo2  

  10.   position: absolute  

編譯成

CSS 

  1. #logo {   

  2.   z-index: 20;   

  3.   position: absolute;   

  4. }   

  5. #logo2 {   

  6.   position: absolute;   

  7.   z-index: 1;   

  8. }  

向上冒泡

stylus:屬性會(huì)“向上冒泡”查找堆棧直到被發(fā)現(xiàn),或者返回null(如果屬性搞不定)下面這個(gè)例子,@color被弄成了blue.

CSS 

  1. body   

  2.   color: red  

  3.   ul   

  4.     li   

  5.       color: blue  

  6.       a   

  7.         background-color: @color  

編譯成

CSS 

  1. body {   

  2.   color: #f00;   

  3. }   

  4. body ul li {   

  5.   color: #00f;   

  6. }   

  7. body ul li a {   

  8.   background-color: #00f;   

  9. }  

Iteration(迭代)

stylus

CSS 

table   

    for row in 1 2 3 4 5   

       tr:nth-child({row})   

         height: 10px * row  

編譯

C# 

  1. table tr:nth-child(1) {   

  2.   height: 10px;   

  3. }   

  4. table tr:nth-child(2) {   

  5.   height: 20px;   

  6. }   

  7. table tr:nth-child(3) {   

  8.   height: 30px;   

  9. }   

  10. table tr:nth-child(4) {   

  11.   height: 40px;   

  12. }   

  13. table tr:nth-child(5) {   

  14.   height: 50px;   

  15. }  

Interpolation(插值)

stylus

CSS 

  1. vendors = webkit moz o ms official   

  2. border-radius()   

  3.     for vendor in vendors   

  4.         if vendor == official   

  5.             border-radius: arguments   

  6.         else   

  7.             -{vendor}-border-radius: arguments   

  8. #content   

  9.     border-radius: 5px  

編譯成

CSS 

  1. #content {   

  2.   -webkit-border-radius: 5px;   

  3.   -moz-border-radius: 5px;   

  4.   -o-border-radius: 5px;   

  5.   -ms-border-radius: 5px;   

  6.   border-radius: 5px;   

  7. }  

Operators(運(yùn)算符)

運(yùn)算符優(yōu)先級(jí)
下表運(yùn)算符優(yōu)先級(jí),從最高到最低:

.
 []
 ! ~ + -
 is defined
 ** * / %
 + -
 ... ..
 <= >= < >
 in
 == is != is not isnt
 is a
 && and || or
 ?:
 = := ?= += -= *= /= %=
 not
 if unless

@import

@import "reset.css"

當(dāng)使用@import沒(méi)有.css擴(kuò)展,會(huì)被認(rèn)為是Stylus片段(如:@import "mixins/border-radius")。

@import工作原理為:遍歷目錄隊(duì)列,并檢查任意目錄中是否有該文件(類似node的require.paths)。該隊(duì)列默認(rèn)為單一路徑,從filename選項(xiàng)的dirname衍生而來(lái)。 因此,如果你的文件名是/tmp/testing/stylus/main.styl,導(dǎo)入將顯現(xiàn)為/tmp/testing/stylus/。

@import也支持索引形式。這意味著當(dāng)你@import blueprint, 則會(huì)理解成blueprint.styl或blueprint/index.styl. 對(duì)于庫(kù)而言,這很有用,既可以展示所有特征與功能,同時(shí)又能導(dǎo)入特征子集。
@font-face

stylus

CSS

  1. @font-face   

  2.   font-family Geo   

  3.   font-style normal  

  4.   src url(fonts/geo_sans_light/GensansLight.ttf)   

  5.   

  6. .ingeo   

  7.   font-family Geo  

編譯成

CSS

  1. @font-face {   

  2.   font-family: Geo;   

  3.   font-style: normal;   

  4.   src: url("fonts/geo_sans_light/GensansLight.ttf");   

  5. }   

  6. .ingeo {   

  7.   font-family: Geo;   

  8. }  

@media

stylus

CSS 

  1. @media print  

  2.   #header  

  3.   #footer  

  4.     display none  

編譯成

CSS

  1. @media print {   

  2.   #header,   

  3.   #footer {   

  4.     display: none;   

  5.   }   

  6. }   

  7.   

  8. @keyframes  

stylus

CSS

  1. @keyframes pulse   

  2.     0%   

  3.       background-color red  

  4.       transform scale(1.0) rotate(0deg)   

  5.     33%   

  6.       background-color blue  

  7.       -webkit-transform scale(1.1) rotate(-5deg)  

編譯成

CSS 

  1. @-moz-keyframes pulse {   

  2.   0% {   

  3.     background-color: #f00;   

  4.     transform: scale(1) rotate(0deg);   

  5.   }   

  6.   33% {   

  7.     background-color: #00f;   

  8.     -webkit-transform: scale(1.1) rotate(-5deg);   

  9.   }   

  10. }   

  11. @-webkit-keyframes pulse {   

  12.   0% {   

  13.     background-color: #f00;   

  14.     transform: scale(1) rotate(0deg);   

  15.   }   

  16.   33% {   

  17.     background-color: #00f;   

  18.     -webkit-transform: scale(1.1) rotate(-5deg);   

  19.   }   

  20. }   

  21. @-o-keyframes pulse {   

  22.   0% {   

  23.     background-color: #f00;   

  24.     transform: scale(1) rotate(0deg);   

  25.   }   

  26.   33% {   

  27.     background-color: #00f;   

  28.     -webkit-transform: scale(1.1) rotate(-5deg);   

  29.   }   

  30. }   

  31. @keyframes pulse {   

  32.   0% {   

  33.     background-color: #f00;   

  34.     transform: scale(1) rotate(0deg);   

  35.   }   

  36.   33% {   

  37.     background-color: #00f;   

  38.     -webkit-transform: scale(1.1) rotate(-5deg);   

  39.   }   

  40. }  

CSS字面量(CSS Literal)

stylus

CSS 

  1. @css {   

  2.   body {   

  3.     font: 14px;   

  4.   }   

  5. }  

編譯成

CSS 

  1. body {   

  2.   font: 14px;   

  3. }  

看完上述內(nèi)容,你們掌握CSS的預(yù)處理框架stylus是怎樣的的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

當(dāng)前題目:CSS的預(yù)處理框架stylus是怎樣的
本文地址:http://chinadenli.net/article12/jiisdc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、定制開(kāi)發(fā)、營(yíng)銷型網(wǎng)站建設(shè)、網(wǎng)站制作響應(yīng)式網(wǎng)站、ChatGPT

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司