Home Web Front-end CSS Tutorial Detailed description of how to use stylus css framework

Detailed description of how to use stylus css framework

Mar 13, 2017 pm 05:45 PM

The editor below will bring you a detailed description of stylus cssframework. The editor thinks it is pretty good, so I will share it with you now and give it as a reference

Stylus is a css language that needs to be compiled, so its own file cannot be directly called by html and needs to be compiled into a css file. Then perform daily loading.

stylus is an excellent CSS compilation language that requires node.js support. The first step is to install node.js

Problem: ctrl+d has no effect during Windows debugging ctrl+c exits ? How to output debugging code directly under windows

Remarks: # means this line is the enter and run line

Official website download nodejs

tar xvf node-v0.10.28.tar.gz    
#  cd node-v0.10.28    
#  ./configure    
# make    
# make install    
# cp /usr/local/bin/node /usr/sbin/
Copy after login


2 node - v Check the node version information. If there is return information, the installation is successful

3 Install stylus

# npm install stylus -gNote: Must find -g Also configure the environment as a global method

4 Debugging Stylus

# stylus   
border-radius()   
  -webkit-border-radius arguments   
  -moz-border-radius arguments   
  border-radius arguments   

body   
  font 12px Helvetica, Arial, sans-serif

a.button   
  border-radius(5px)
Copy after login


Enter Ctrl+D to debug the return result

See if it will Return

body {   
  font: 12px Helvetica, Arial, sans-serif;   
}   
a.button {   
  -webkit-border-radius: 5px;   
  -moz-border-radius: 5px;   
  border-radius: 5px;   
}
Copy after login


5 Compilation of styus file

Create a test.styl file with the following content:

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

body   
  font 12px Helvetica, Arial, sans-serif

a.button   
  border-radius 5px
Copy after login


Save and close, run the following command on the command line:

# stylus --compress < test.styl > test.css

See if you get a test .css file, see if the content is as follows:

body{   
font:12px Helvetica,Arial,sans-serif
}   
a.button{   
-webkit-border-radius:5px;   
-moz-border-radius:5px;   
border-radius:5px
}
Copy after login


Such a stylus file will be compiled into a css file that can be called by html.

Appendix:

Compile file example
stylus also accepts files and directories. For example, a directory named css will compile and output a .css file in the same directory.

$ stylus css The following will be output to ./public/stylesheets:

$ stylus css --out public/stylesheets or some files:

$ stylus one. styl two.styl For development purposes, you can use the linenos option to issue instructions to display the Stylus file name and line number in the generated CSS.

$ stylus --line-numbers or the firebug option if you want to use firebug's FireStylus extension.

$ stylus --firebug Convert CSS
If you want to convert CSS into concise Stylus syntax, you can use the --css flag.

Output through standard input:

$ stylus --css < test.css > test.styl Output the .styl file with the same base name.

$ stylus --css test.css output specific target:

$ stylus --css test.css /tmp/out.stylCSSPropertiesHelp
On OS X, stylus help will open your default browser and display help documentation for the given property.

$ stylus help box-shadow Shell Interactive (Interactive Shell)
Stylus REPL (Read-Eval-Print-Loop) or "Shell Interactive (Interactive Shell)" allows You play with Stylus' Expressions directly on the terminal.

Note that only expressions can take effect, not selectors and the like. For simplicity, we add the -i or --interactive flag:

$ stylus -i
> color = white
=> #fff
> color - rgb(200, 50,0)
=> #37cdff
> color
=> #fff
> color -= rgb(200,50,0)
=> #37cdff
> color
=> #37cdff
> rgba(color, 0.5)
=> rgba(55,205,255,0.5) using the plug-in
In this example we will use the nibStylus plug-in to Explain its CLI usage.

Suppose we have the following Stylus, which imports nib and uses nib's linear-gradient() method:

@import 'nib'

body
background: linear-gradient(20px top, white, black) The first thing we try to render via standard input and output using stylus(1) may look like this:

$ stylus < ; test.styl This may generate an error like the following because Stylus doesn't know where to find the nib.

Error: stdin:3
1|
2|
> 3| @ import 'nib'
4|
5| body
6| background: linear-gradient(20px top, white, black) For simple application of Stylus API's plug-ins, we can Add search path. By using --include or the -I flag:

$ stylus < test.styl --include ../nib/lib now generates the following content. You may have noticed that gradient-data-uri() and create-gradient-image() are output in literal form. This is because, when the plugin provides the JavaScript API, it is not enough to expose the path of the plugin. However, if all we want is pure Stylus nibfunction, that's enough.

body {   
  background: url(gradient-data-uri(create-gradient-image(20px, top)));   
  background: -webkit-gradient(linear, left top, left bottombottom, color-stop(0, #fff), color-stop(1, #000));   
  background: -webkit-linear-gradient(top, #fff 0%, #000 100%);   
  background: -moz-linear-gradient(top, #fff 0%, #000 100%);   
  background: linear-gradient(top, #fff 0%, #000 100%);   
}
Copy after login


因此,我们需要做的是使用--use或-u标志。其会找寻node模块(有或者没有.js扩展名)路径,这里的require()模块或调用style.use(fn())来暴露该插件(定义js函数等)。

$ stylus < test.styl --use ../nib/lib/nib生成为:

body {   
  background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAUCAYAAABMDlehAAAABmJLR0QA/wD/AP+gvaeTAAAAI0lEQVQImWP4+fPnf6bPnz8zMH358oUBwkIjKJBgYGNj+w8Aphk4blt0EcMAAAAASUVORK5CYII=");   
  background: -webkit-gradient(linear, left top, left bottombottom, color-stop(0, #fff), color-stop(1, #000));   
  background: -webkit-linear-gradient(top, #fff 0%, #000 100%);   
  background: -moz-linear-gradient(top, #fff 0%, #000 100%);   
  background: linear-gradient(top, #fff 0%, #000 100%);   
}
Copy after login


nodemon 插件

# npm install nodemon -g

var css = require("stylus"),    
    str = require("fs").readFileSync("style.styl", "utf8");   

css.render(str, { filename: "stylus.styl" }, function(err, css) {   
    if (err) throw err;   
    var http = require(&#39;http&#39;);   
    http.createServer(function (req, res) {   
        res.writeHead(200, {&#39;Content-Type&#39;: &#39;text/css&#39;});   
        res.end(css);   
    }).listen(1337, &#39;127.0.0.1&#39;);   
    console.log(&#39;已经启动 http://www.php.cn/:1337/&#39;);   
});
Copy after login


以上这篇stylus css 框架使用方法深入解析就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持PHP中文网。

The above is the detailed content of Detailed description of how to use stylus css framework. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Demystifying Screen Readers: Accessible Forms & Best Practices Demystifying Screen Readers: Accessible Forms & Best Practices Mar 08, 2025 am 09:45 AM

This is the 3rd post in a small series we did on form accessibility. If you missed the second post, check out "Managing User Focus with :focus-visible". In

Create a JavaScript Contact Form With the Smart Forms Framework Create a JavaScript Contact Form With the Smart Forms Framework Mar 07, 2025 am 11:33 AM

This tutorial demonstrates creating professional-looking JavaScript forms using the Smart Forms framework (note: no longer available). While the framework itself is unavailable, the principles and techniques remain relevant for other form builders.

Adding Box Shadows to WordPress Blocks and Elements Adding Box Shadows to WordPress Blocks and Elements Mar 09, 2025 pm 12:53 PM

The CSS box-shadow and outline properties gained theme.json support in WordPress 6.1. Let&#039;s look at a few examples of how it works in real themes, and what options we have to apply these styles to WordPress blocks and elements.

Working With GraphQL Caching Working With GraphQL Caching Mar 19, 2025 am 09:36 AM

If you’ve recently started working with GraphQL, or reviewed its pros and cons, you’ve no doubt heard things like “GraphQL doesn’t support caching” or

Making Your First Custom Svelte Transition Making Your First Custom Svelte Transition Mar 15, 2025 am 11:08 AM

The Svelte transition API provides a way to animate components when they enter or leave the document, including custom Svelte transitions.

Comparing the 5 Best PHP Form Builders (And 3 Free Scripts) Comparing the 5 Best PHP Form Builders (And 3 Free Scripts) Mar 04, 2025 am 10:22 AM

This article explores the top PHP form builder scripts available on Envato Market, comparing their features, flexibility, and design. Before diving into specific options, let's understand what a PHP form builder is and why you'd use one. A PHP form

Show, Don't Tell Show, Don't Tell Mar 16, 2025 am 11:49 AM

How much time do you spend designing the content presentation for your websites? When you write a new blog post or create a new page, are you thinking about

What the Heck Are npm Commands? What the Heck Are npm Commands? Mar 15, 2025 am 11:36 AM

npm commands run various tasks for you, either as a one-off or a continuously running process for things like starting a server or compiling code.

See all articles