目次
スタイラスの紹介
ドキュメントリファレンス
Stylusのインストール
CSSを生成します
コマンドラインでstylusExample/を作成します
grunt 生成
スタイラスアプリケーション
Stylus をお試しください!
nibSt にコンパイルされましたylus プラグイン
ネスティング(入れ子)
柔軟な構文(柔軟な使い方)
フレキシブル&(フレキシブル& )
Functionsメソッド
戻り値
デフォルトパラメータにコンパイルされます
関数本体
複数の戻り値
Variables(変数)
共通メソッド
変数は属性に配置されます
ブロックにコンパイルされる属性 参照
属性にコンパイルされます
向上冒泡
Iteration(迭代)
Interpolation(插值)
Operators(运算符)
@import
@font-face
@media
@keyframes
CSS字面量(CSS Literal)
ホームページ ウェブフロントエンド htmlチュートリアル stylus_html/css_WEB-ITnose の使用を開始する

stylus_html/css_WEB-ITnose の使用を開始する

Jun 24, 2016 am 11:45 AM
stylus

スタイラスの紹介

それは一体何ですか?開発にとって、CSS の弱点は静的であることです。開発効率を本当に向上させるツールが必要です。LESS と SASS はこの点で貢献しています。

Stylus は、Node.js コミュニティによって 2010 年に作成された CSS 前処理フレームワークであり、主に Node プロジェクトの CSS 前処理をサポートするために使用されます。そのため、Stylus は、堅牢で動的、表現力豊かな CSS を作成できる新しい言語です。これは比較的新しく、本質的に行うことは SASS/LESS などに似ています。学ぶべきことはたくさんあるはずなので、CSS コードを記述するためのスクリプトに似ています。

Stylus はデフォルトでファイル拡張子として .styl を使用し、多様な CSS 構文をサポートします。

Stylus は機能がより強力で、js とより密接に関連しています。そこで私は Stylus を選択し、しばらく SASS で遊んでみました。主な理由は、これが実行するのに Ruby に依存していたため、SASS の使用をやめたからです。

ドキュメントリファレンス

公式Stylus API
Zhang Xinxu中国語翻訳
Stylusを試してください!

Stylusのインストール

グローバルインストール、インストール前にnodejsをインストールする必要があります。インストール方法を検索してください。

$ 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:  -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を生成します

コマンドラインでstylusExample/を作成します

、次にその中にスタイラスファイルを特別に保存するためのsrcディレクトリを作成し、その中にexample.stylファイルを作成します。次に stylusExample ディレクトリ

$ stylus --compress src/

で以下のコマンドを実行すると、コンパイルされた src/example.css が出力されます。これは --compress パラメータを持ってきたことを意味します。圧縮 CSS ファイルが生成されました。

$ stylus --css css/example.css css/out.styl CSSをstylに変換します
$ stylus help box-shadow CSSプロパティヘルプ
$ stylus --css test.css 同じベース名で.stylファイルを出力します

grunt 生成

grunt 生成は、具体的には Grunt チュートリアル - フロントエンド自動化のチュートリアルを書きました。

stylusExample ディレクトリに 2 つのファイルを作成します。これらの 2 つのファイルは grunt に必要なファイルです。

package.json: プロジェクトのメタデータを保存するために使用されます。
Gruntfile.js: タスクを構成または定義し、Grunt プラグインをロードするために使用されます。

package.json content

json{  "name": "test",  "version": "1.0.0",  "description": "测试的例子",  "repository": {    "type": "git",    "url": ""  }}
ログイン後にコピー

次に、これらのプラグインをインストールすると、スタイラス ファイルの変更が自動的に生成され、対応するファイル ディレクトリに生成されます。エラーが報告された場合は、コマンドラインの前に sudo を追加して、最大の実行権限を付与する必要があります。

npm install grunt --save-dev
npm install grunt-contrib-watch --save-dev: ファイルの変更を監視し、対応するアクションを実行します。 npm>>
npm install grunt-contrib-stylus --save-dev: stylus writes styl Output css npm>>

インストールするとこのような警告が表示されます npm WARN package.json test@1.0.0 README データがありません 無視できます不快に感じる場合は、stylusExample ディレクトリの下に README.md ファイルを作成し、内容を入力する必要があります。コマンド echo "#stylus learning" >> README.md を実行することもできます

プラグインが実行されると、package.json ファイルは次のようになります。

json{  "name": "test",  "version": "1.0.0",  "description": "测试的例子",  "repository": {    "type": "git",    "url": ""  },  "devDependencies": {    "grunt": "^0.4.5",    "grunt-contrib-stylus": "^0.21.0",    "grunt-contrib-watch": "^0.6.1"  }}
ログイン後にコピー

現時点では、これらのプラグインを使用してタスクを完了し、実行タスクを Gruntfile.js に記述する必要があります。

js/// 包装函数module.exports = function(grunt) {    // 任务配置,所有插件的配置信息    grunt.initConfig({        pkg: grunt.file.readJSON(&#39;package.json&#39;),        stylus:{            build: {                options: {                    linenos: false,                    compress: true                },                files: [{                    &#39;css/index.css&#39;: [&#39;src/index.styl&#39;]                }]            }        },        // watch插件的配置信息        watch: {            another: {                files: [&#39;css/*&#39;,&#39;src/*.styl&#39;],                tasks: [&#39;stylus&#39;],                options: {                    livereload: 1337                }            }        }    });    // 告诉grunt我们将使用插件    grunt.loadNpmTasks(&#39;grunt-contrib-watch&#39;);    grunt.loadNpmTasks(&#39;grunt-contrib-stylus&#39;);    // 告诉grunt当我们在终端中输入grunt时需要做些什么    grunt.registerTask(&#39;default&#39;, [&#39;watch&#39;]);};
ログイン後にコピー

上記を読んで理解してください。ディレクトリは正しいので、通知する必要はありません。この時点で、スタイラス

スタイラスアプリケーション

を使ってプレイできます。ここからが実際にプレイを開始する時間です。

Stylus をお試しください!

stylus

body,html    margin:0    padding:0
ログイン後にコピー

cssbody,html {  margin: 0;  padding: 0;}
ログイン後にコピー

stylus にコンパイルされました: 強力な機能豊富な言語

-pos(type, args)  i = 0  position: unquote(type)  {args[i]}: args[i + 1] is a &#39;unit&#39; ? args[i += 1] : 0  {args[i += 1]}: args[i + 1] is a &#39;unit&#39; ? args[i += 1] : 0absolute()  -pos(&#39;absolute&#39;, arguments)fixed()  -pos(&#39;fixed&#39;, arguments)#prompt  absolute: top 150px left 5px  width: 200px  margin-left: -(@width / 2)#logo  fixed: top left
ログイン後にコピー

css#prompt {  position: absolute;  top: 150px;  left: 5px;  width: 200px;  margin-left: -100px;}#logo {  position: fixed;  top: 0;  left: 0;}
ログイン後にコピー

nibSt にコンパイルされましたylus プラグイン

stylus

@import &#39;nib&#39;body  background: linear-gradient(20px top, white, black)
ログイン後にコピー

コンパイルinto

cssbody {  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);}
ログイン後にコピー

ネスティング(入れ子)

stylus

header    #logo        border:1px solid red
ログイン後にコピー

Compile into

cssheader #logo {  border: 1px solid #f00;}
ログイン後にコピー

柔軟な構文(柔軟な使い方)

stylus

body    font 14px/1.5 Helvetica, arial, sans-serif    button    button.button    input[type=&#39;button&#39;]    input[type=&#39;submit&#39;]        border-radius 5pxheader     #logo,div        font-size:14px
ログイン後にコピー

Compile

cssbody {  font: 14px/1.5 Helvetica, arial, sans-serif;}body button,body button.button,body input[type=&#39;button&#39;] {  border-radius: 5px;}header #logo,header div {  font-size: 14px;}
ログイン後にコピー

フレキシブル&(フレキシブル& )

stylus

ul    li a        display: block        color: blue        padding: 5px        html.ie &            padding: 6px        &:hover            color: red
ログイン後にコピー

Compile into

cssul 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: valbutton     border-radius(5px);
ログイン後にコピー

Compile into

cssbutton {  -webkit-border-radius: 5px;  -moz-border-radius: 5px;  border-radius: 5px;}
ログイン後にコピー

パラメータなし

スタイラス

border-radius()    -webkit-border-radius: arguments    -moz-border-radius: arguments    border-radius: argumentsbutton     border-radius: 5px 10px;
ログイン後にコピー

cssbutton {  -webkit-border-radius: 5px 10px;  -moz-border-radius: 5px 10px;  border-radius: 5px 10px;}
ログイン後にコピー

デフォルトパラメータにコンパイルされます

パラメータなし

スタイラス

add(a, b = a)  a + badd(10, 5)// => 15add(10)// => 20
ログイン後にコピー

関数本体

各パラメータに割り当てがあるため、単位は組み込みのunit()を通じてpxに変更されますしたがって、単位変換は無視できます。

add(a, b = a)  a = unit(a, px)  b = unit(b, px)  a + badd(15%, 10deg)// => 25
ログイン後にコピー

複数の戻り値

組み込みのunit()を通じて単位をpxに変換します。値は各パラメータに割り当てられているため、単位の変換は無視できます。

sizes() 15px 10pxsizes()[0]// => 15px
ログイン後にコピー

Variables(変数)

共通メソッド

stylus

font-size = 14pxbody    font font-size Arial, sans-seri
ログイン後にコピー

cssbody {  font: 14px Arial, sans-seri;}
ログイン後にコピー
にコンパイルされます

変数は属性に配置されます

stylus

#prompt    position: absolute    top: 150px    left: 50%    width: w = 200px    margin-left: -(w / 2)
ログイン後にコピー

css#prompt {  position: absolute;  top: 150px;  left: 50%;  width: 200px;  margin-left: -100px;}
ログイン後にコピー

ブロックにコンパイルされる属性 参照

stylus

#prompt    position: absolute    width: 200px    margin-left: -(@width / 2)
ログイン後にコピー

へのアクセスは、条件付きで属性を定義する

css#prompt {  position: absolute;  width: 200px;  margin-left: -100px;}
ログイン後にコピー

属性にコンパイルされます

stylus: ただし、z-index が事前に指定されていない場合に限り、z-index 値 1 を指定します。 :

position()  position: arguments  z-index: 1 unless @z-index#logo  z-index: 20  position: absolute#logo2  position: absolute
ログイン後にコピー

css#logo {  z-index: 20;  position: absolute;}#logo2 {  position: absolute;  z-index: 1;}
ログイン後にコピー

にコンパイルされます

向上冒泡

stylus:属性会“向上冒泡”查找堆栈直到被发现,或者返回null(如果属性搞不定)下面这个例子,@color被弄成了blue.

body  color: red  ul    li      color: blue      a        background-color: @color
ログイン後にコピー

编译成

cssbody {  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
ログイン後にコピー

编译成

csstable 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 officialborder-radius()    for vendor in vendors        if vendor == official            border-radius: arguments        else            -{vendor}-border-radius: arguments#content    border-radius: 5px
ログイン後にコピー

编译成

css#content {  -webkit-border-radius: 5px;  -moz-border-radius: 5px;  -o-border-radius: 5px;  -ms-border-radius: 5px;  border-radius: 5px;}
ログイン後にコピー

Operators(运算符)

运算符优先级
下表运算符优先级,从最高到最低:

. [] ! ~ + - is defined ** * / % + - ... .. <= >= < > in == is != is not isnt is a && and || or ?: = := ?= += -= *= /= %= not if unless
ログイン後にコピー

@import

@import "reset.css"

当使用@import没有.css扩展,会被认为是Stylus片段(如:@import "mixins/border-radius")。

@import工作原理为:遍历目录队列,并检查任意目录中是否有该文件(类似node的require.paths)。该队列默认为单一路径,从filename选项的dirname衍生而来。 因此,如果你的文件名是/tmp/testing/stylus/main.styl,导入将显现为/tmp/testing/stylus/。

@import也支持索引形式。这意味着当你@import blueprint, 则会理解成blueprint.styl或blueprint/index.styl. 对于库而言,这很有用,既可以展示所有特征与功能,同时又能导入特征子集。

@font-face

stylus

@font-face  font-family Geo  font-style normal  src url(fonts/geo_sans_light/GensansLight.ttf).ingeo  font-family Geo
ログイン後にコピー

编译成

css@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
ログイン後にコピー

编译成

css@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)
ログイン後にコピー

编译成

css@-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;  }}
ログイン後にコピー

编译成

cssbody {  font: 14px;}
ログイン後にコピー

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

&lt; Progress&gt;の目的は何ですか 要素? &lt; Progress&gt;の目的は何ですか 要素? Mar 21, 2025 pm 12:34 PM

この記事では、HTML&lt; Progress&gt;について説明します。要素、その目的、スタイリング、および&lt; meter&gt;との違い要素。主な焦点は、&lt; Progress&gt;を使用することです。タスクの完了と&lt; Meter&gt; statiの場合

&lt; datalist&gt;の目的は何ですか 要素? &lt; datalist&gt;の目的は何ですか 要素? Mar 21, 2025 pm 12:33 PM

この記事では、HTML&lt; Datalist&GT;について説明します。オートコンプリートの提案を提供し、ユーザーエクスペリエンスの改善、エラーの削減によりフォームを強化する要素。

&lt; meter&gt;の目的は何ですか 要素? &lt; meter&gt;の目的は何ですか 要素? Mar 21, 2025 pm 12:35 PM

この記事では、html&lt; meter&gt;について説明します。要素は、範囲内でスカラーまたは分数値を表示するために使用され、Web開発におけるその一般的なアプリケーション。それは差別化&lt; Meter&gt; &lt; Progress&gt;およびex

ビューポートメタタグとは何ですか?レスポンシブデザインにとってなぜそれが重要なのですか? ビューポートメタタグとは何ですか?レスポンシブデザインにとってなぜそれが重要なのですか? Mar 20, 2025 pm 05:56 PM

この記事では、モバイルデバイスのレスポンシブWebデザインに不可欠なViewportメタタグについて説明します。適切な使用により、最適なコンテンツのスケーリングとユーザーの相互作用が保証され、誤用が設計とアクセシビリティの問題につながる可能性があることを説明しています。

&lt; iframe&gt;の目的は何ですか タグ?使用する際のセキュリティ上の考慮事項は何ですか? &lt; iframe&gt;の目的は何ですか タグ?使用する際のセキュリティ上の考慮事項は何ですか? Mar 20, 2025 pm 06:05 PM

この記事では、&lt; iframe&gt;外部コンテンツをWebページ、その一般的な用途、セキュリティリスク、およびオブジェクトタグやAPIなどの代替案に埋め込む際のタグの目的。

HTMLは初心者のために簡単に学ぶことができますか? HTMLは初心者のために簡単に学ぶことができますか? Apr 07, 2025 am 12:11 AM

HTMLは、簡単に学習しやすく、結果をすばやく見ることができるため、初心者に適しています。 1)HTMLの学習曲線はスムーズで簡単に開始できます。 2)基本タグをマスターして、Webページの作成を開始します。 3)柔軟性が高く、CSSおよびJavaScriptと組み合わせて使用​​できます。 4)豊富な学習リソースと最新のツールは、学習プロセスをサポートしています。

HTML、CSS、およびJavaScriptの役割:コアの責任 HTML、CSS、およびJavaScriptの役割:コアの責任 Apr 08, 2025 pm 07:05 PM

HTMLはWeb構造を定義し、CSSはスタイルとレイアウトを担当し、JavaScriptは動的な相互作用を提供します。 3人はWeb開発で職務を遂行し、共同でカラフルなWebサイトを構築します。

HTMLでの開始タグの例は何ですか? HTMLでの開始タグの例は何ですか? Apr 06, 2025 am 12:04 AM

Anexampleapalofastartingtaginhtmlis、それはaperginsaparagraph.startingtagsaresentionentientiontheyinitiateelements、definetheirtypes、およびarecrucialforurturingwebpagesandcontingthomedomを構築します。

See all articles