成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

stylus入門(mén)使用方法

LiuZh / 2216人閱讀

摘要:默認(rèn)使用的作為文件擴(kuò)展名,支持多樣性的語(yǔ)法。功能上更為強(qiáng)壯,和聯(lián)系更加緊密。所以我選擇,玩兒過(guò)一段時(shí)間,主要是這玩意依賴運(yùn)行,所以我放棄使用了。這樣就算是安裝完了,也可以正常使用。用于保存項(xiàng)目元數(shù)據(jù)。

stylus介紹

是個(gè)什么鬼?對(duì)于開(kāi)發(fā)來(lái)說(shuō),CSS的弱點(diǎn)在于靜態(tài)化。我們需要一個(gè)真正能提高開(kāi)發(fā)效率的工具,LESSSASS都在這方面做了一些貢獻(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)該是有很多借鑒,所以近似腳本的方式去寫(xiě)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      Opens help info for  in
                  your default browser. (OS X only)
Options:

  -u, --use         Utilize the stylus plugin at 
  -i, --interactive       Start interactive REPL
  -w, --watch             Watch file(s) for changes and re-compile
  -o, --out          Output to  when passing files
  -C, --css  [dest]  Convert CSS input to Stylus
  -I, --include     Add  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 目錄專門(mén)存放 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怎么玩兒,俺寫(xiě)了個(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)容

{
  "name": "test",
  "version": "1.0.0",
  "description": "測(cè)試的例子",
  "repository": {
    "type": "git",
    "url": ""
  }
}

然后安裝必備插件,這些插件讓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編寫(xiě)styl輸出css npm>>

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

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

{
  "name": "test",
  "version": "1.0.0",
  "description": "測(cè)試的例子",
  "repository": {
    "type": "git",
    "url": ""
  },
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-contrib-stylus": "^0.21.0",
    "grunt-contrib-watch": "^0.6.1"
  }
}

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

/// 包裝函數(shù)
module.exports = function(grunt) {
    // 任務(wù)配置,所有插件的配置信息
    grunt.initConfig({
        pkg: grunt.file.readJSON("package.json"),
        stylus:{
            build: {
                options: {
                    linenos: false,
                    compress: true
                },
                files: [{
                    "css/index.css": ["src/index.styl"]
                }]
            }
        },
        // watch插件的配置信息
        watch: {
            another: {
                files: ["css/*","src/*.styl"],
                tasks: ["stylus"],
                options: {
                    livereload: 1337
                }
            }
        }
    });
    // 告訴grunt我們將使用插件
    grunt.loadNpmTasks("grunt-contrib-watch");
    grunt.loadNpmTasks("grunt-contrib-stylus");
    // 告訴grunt當(dāng)我們?cè)诮K端中輸入grunt時(shí)需要做些什么
    grunt.registerTask("default", ["watch"]);
};

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

Stylus應(yīng)用

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

Try Stylus!

stylus

body,html
    margin:0
    padding:0

編譯成

body,
html {
  margin: 0;
  padding: 0;
}

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

-pos(type, args)
  i = 0
  position: unquote(type)
  {args[i]}: args[i + 1] is a "unit" ? args[i += 1] : 0
  {args[i += 1]}: args[i + 1] is a "unit" ? args[i += 1] : 0

absolute()
  -pos("absolute", arguments)

fixed()
  -pos("fixed", arguments)

#prompt
  absolute: top 150px left 5px
  width: 200px
  margin-left: -(@width / 2)

#logo
  fixed: top left

編譯成

#prompt {
  position: absolute;
  top: 150px;
  left: 5px;
  width: 200px;
  margin-left: -100px;
}
#logo {
  position: fixed;
  top: 0;
  left: 0;
}
nibStylus插件

stylus

@import "nib"
body
  background: linear-gradient(20px top, white, black) 

編譯成

body {
  background: -webkit-linear-gradient(20px top, #fff, #000);
  background: -moz-linear-gradient(20px top, #fff, #000);
  background: -o-linear-gradient(20px top, #fff, #000);
  background: -ms-linear-gradient(20px top, #fff, #000);
  background: linear-gradient(20px top, #fff, #000);
}
Nesting(嵌套)

stylus

header
    #logo
        border:1px solid red

編譯成

header #logo {
  border: 1px solid #f00;
}
Flexible syntax(靈活的用法)

stylus

body
    font 14px/1.5 Helvetica, arial, sans-serif
    button
    button.button
    input[type="button"]
    input[type="submit"]
        border-radius 5px
        
header 
    #logo,div
        font-size:14px

編譯成

body {
  font: 14px/1.5 Helvetica, arial, sans-serif;
}
body button,
body button.button,
body input[type="button"] {
  border-radius: 5px;
}
header #logo,
header div {
  font-size: 14px;
}
Flexible &(靈活&)

stylus

ul
    li a
        display: block
        color: blue
        padding: 5px
        html.ie &
            padding: 6px
        &:hover
            color: red

編譯成

ul li a {
  display: block;
  color: #00f;
  padding: 5px;
}
html.ie ul li a {
  padding: 6px;
}
ul li a:hover {
  color: #f00;
}
Functions 方法 返回值

stylus

border-radius(val)
    -webkit-border-radius: val
    -moz-border-radius: val
    border-radius: val

button 
    border-radius(5px);

編譯成

button {
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  border-radius: 5px;
}
Transparent mixins

不帶參數(shù)

stylus

border-radius()
    -webkit-border-radius: arguments
    -moz-border-radius: arguments
    border-radius: arguments

button 
    border-radius: 5px 10px;

編譯成

button {
  -webkit-border-radius: 5px 10px;
  -moz-border-radius: 5px 10px;
  border-radius: 5px 10px;
}
默認(rèn)參數(shù)

不帶參數(shù)

stylus

add(a, b = a)
  a + b

add(10, 5)
// => 15

add(10)
// => 20
函數(shù)體

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

add(a, b = a)
  a = unit(a, px)
  b = unit(b, px)
  a + b

add(15%, 10deg)
// => 25
多個(gè)返回值

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

sizes()
 15px 10px

sizes()[0]
// => 15px
Variables(變量) 常用方法

stylus

font-size = 14px

body
    font font-size Arial, sans-seri

編譯成

body {
  font: 14px Arial, sans-seri;
}
變量放在屬性中

stylus

#prompt
    position: absolute
    top: 150px
    left: 50%
    width: w = 200px
    margin-left: -(w / 2)

編譯成

#prompt {
  position: absolute;
  top: 150px;
  left: 50%;
  width: 200px;
  margin-left: -100px;
}
塊屬性訪問(wèn)引用

stylus

#prompt
    position: absolute
    width: 200px
    margin-left: -(@width / 2)

編譯成

#prompt {
  position: absolute;
  width: 200px;
  margin-left: -100px;
}
屬性有條件地定義屬性

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

position()
  position: arguments
  z-index: 1 unless @z-index

#logo
  z-index: 20
  position: absolute

#logo2
  position: absolute

編譯成

#logo {
  z-index: 20;
  position: absolute;
}
#logo2 {
  position: absolute;
  z-index: 1;
}
向上冒泡

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

body
  color: red
  ul
    li
      color: blue
      a
        background-color: @color

編譯成

body {
  color: #f00;
}
body ul li {
  color: #00f;
}
body ul li a {
  background-color: #00f;
}
Iteration(迭代)

stylus

table
    for row in 1 2 3 4 5
        tr:nth-child({row})
            height: 10px * row

編譯成

table tr:nth-child(1) {
  height: 10px;
}
table tr:nth-child(2) {
  height: 20px;
}
table tr:nth-child(3) {
  height: 30px;
}
table tr:nth-child(4) {
  height: 40px;
}
table tr:nth-child(5) {
  height: 50px;
}
Interpolation(插值)

stylus

vendors = webkit moz o ms official
border-radius()
    for vendor in vendors
        if vendor == official
            border-radius: arguments
        else
            -{vendor}-border-radius: arguments
#content
    border-radius: 5px

編譯成

#content {
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  -o-border-radius: 5px;
  -ms-border-radius: 5px;
  border-radius: 5px;
}
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.stylblueprint/index.styl. 對(duì)于庫(kù)而言,這很有用,既可以展示所有特征與功能,同時(shí)又能導(dǎo)入特征子集。

@font-face

stylus

@font-face
  font-family Geo
  font-style normal
  src url(fonts/geo_sans_light/GensansLight.ttf)

.ingeo
  font-family Geo

編譯成

@font-face {
  font-family: Geo;
  font-style: normal;
  src: url("fonts/geo_sans_light/GensansLight.ttf");
}
.ingeo {
  font-family: Geo;
}
@media

stylus

@media print
  #header
  #footer
    display none

編譯成

@media print {
  #header,
  #footer {
    display: none;
  }
}
@keyframes

stylus

@keyframes pulse
    0%
      background-color red
      transform scale(1.0) rotate(0deg)
    33%
      background-color blue
      -webkit-transform scale(1.1) rotate(-5deg)

編譯成

@-moz-keyframes pulse {
  0% {
    background-color: #f00;
    transform: scale(1) rotate(0deg);
  }
  33% {
    background-color: #00f;
    -webkit-transform: scale(1.1) rotate(-5deg);
  }
}
@-webkit-keyframes pulse {
  0% {
    background-color: #f00;
    transform: scale(1) rotate(0deg);
  }
  33% {
    background-color: #00f;
    -webkit-transform: scale(1.1) rotate(-5deg);
  }
}
@-o-keyframes pulse {
  0% {
    background-color: #f00;
    transform: scale(1) rotate(0deg);
  }
  33% {
    background-color: #00f;
    -webkit-transform: scale(1.1) rotate(-5deg);
  }
}
@keyframes pulse {
  0% {
    background-color: #f00;
    transform: scale(1) rotate(0deg);
  }
  33% {
    background-color: #00f;
    -webkit-transform: scale(1.1) rotate(-5deg);
  }
}
CSS字面量(CSS Literal)

stylus

@css {
  body {
    font: 14px;
  }
}

編譯成

body {
  font: 14px;
}
工具

sublime 插件 Stylus Clean Completions 代碼提示

Stylus

文檔參考

官方Stylus API
張?chǎng)涡裰形姆g
Try Stylus!

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/111054.html

相關(guān)文章

  • 直接使用sublime編譯stylus

    摘要:介紹是一個(gè)的預(yù)處理框架,年產(chǎn)生,來(lái)自社區(qū),主要用來(lái)給項(xiàng)目進(jìn)行預(yù)處理支持,所以是一種新型語(yǔ)言,可以創(chuàng)建健壯的動(dòng)態(tài)的富有表現(xiàn)力的。 stylus介紹 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...

    darkerXi 評(píng)論0 收藏0
  • 直接使用sublime編譯stylus

    摘要:介紹是一個(gè)的預(yù)處理框架,年產(chǎn)生,來(lái)自社區(qū),主要用來(lái)給項(xiàng)目進(jìn)行預(yù)處理支持,所以是一種新型語(yǔ)言,可以創(chuàng)建健壯的動(dòng)態(tài)的富有表現(xiàn)力的。 stylus介紹 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...

    Enlightenment 評(píng)論0 收藏0
  • wepback入門(mén)到放棄

    摘要:四配置配置規(guī)則放在的數(shù)組里,每個(gè)是一個(gè)對(duì)象,是正則匹配,匹配文件后綴名,是要用是數(shù)組是所需要的是要加載哪些文件,是忽略掉哪些文件。實(shí)現(xiàn)解析,用會(huì)在寫(xiě)入在文件頂端導(dǎo)入中加入插件。 最近研究webpack略有小成,特此寫(xiě)篇博客。雖然webpack有官網(wǎng)api,但是個(gè)人認(rèn)為webpack api一點(diǎn)都不人性化, 不自己研究研究,根本看不懂。今天先從寫(xiě)webpack-dev-server開(kāi)始。...

    blastz 評(píng)論0 收藏0
  • 2017年2月份前端資源分享

    平日學(xué)習(xí)接觸過(guò)的網(wǎng)站積累,以每月的形式發(fā)布。2017年以前看這個(gè)網(wǎng)址:http://www.kancloud.cn/jsfron... 1. Javascript 前端生成好看的二維碼 十大經(jīng)典排序算法(帶動(dòng)圖演示) 為什么知乎前端圈普遍認(rèn)為H5游戲和H5展示的JSer 個(gè)人整理和封裝的YU.js庫(kù)|中文詳細(xì)注釋|供新手學(xué)習(xí)使用 擴(kuò)展JavaScript語(yǔ)法記錄 - 掉坑初期工具 漢字拼音轉(zhuǎn)換...

    lily_wang 評(píng)論0 收藏0
  • 2017年2月份前端資源分享

    平日學(xué)習(xí)接觸過(guò)的網(wǎng)站積累,以每月的形式發(fā)布。2017年以前看這個(gè)網(wǎng)址:http://www.kancloud.cn/jsfron... 1. Javascript 前端生成好看的二維碼 十大經(jīng)典排序算法(帶動(dòng)圖演示) 為什么知乎前端圈普遍認(rèn)為H5游戲和H5展示的JSer 個(gè)人整理和封裝的YU.js庫(kù)|中文詳細(xì)注釋|供新手學(xué)習(xí)使用 擴(kuò)展JavaScript語(yǔ)法記錄 - 掉坑初期工具 漢字拼音轉(zhuǎn)換...

    chengjianhua 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<