Home Web Front-end HTML Tutorial styluscss Framework usage_html/css_WEB-ITnose

styluscss Framework usage_html/css_WEB-ITnose

Jun 24, 2016 pm 12:00 PM
Instructions frame

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

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

1

    # apt-get update      # apt-get install -y python-software-properties software-properties-common # add-apt-repository ppa:chris-lea/node.js # apt-get update # apt-get install nodejs 
Copy after login

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

3 Install stylus

# npm install stylus
Copy after login

4 Debugging Stylus (Ctrl D)

# styusborder-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

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

Compilation of 5 styus files

Create a test.styl file, the file content is as follows:

 1 border-radius() 2   -webkit-border-radius arguments 3   -moz-border-radius arguments 4   border-radius arguments 5    6 body 7   font 12px Helvetica, Arial, sans-serif 8    9 a.button10   border-radius 5px
Copy after login

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

# stylus --compress < test.styl > test.css
Copy after login

See if it is correct Obtain a test.css file and see if the content is as follows:

1 body{2 font:12px Helvetica,Arial,sans-serif3 }4 a.button{5 -webkit-border-radius:5px;6 -moz-border-radius:5px;7 border-radius:5px8 }
Copy after login

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

Appendix:

Example of compiled file

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
Copy after login

The following will be output to ./public/stylesheets:

$ stylus css --out public/stylesheets
Copy after login

or some files:

$ stylus one.styl two.styl
Copy after login

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 <path>
Copy after login

Or the firebug option if you want to use the FireStylus extension for firebug.

$ stylus --firebug <path>
Copy after login
Convert CSS

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

Output via standard input:

$ stylus --css < test.css > test.styl
Copy after login

Output .styl files with the same base name.

$ stylus --css test.css
Copy after login

Output specific targets:

$ stylus --css test.css /tmp/out.styl
Copy after login
Help for CSS properties

On OS X, stylus help will open your default browser and display the given < Help documentation for ;prop> properties.

$ stylus help box-shadow
Copy after login
Interactive Shell

Stylus REPL (Read-Eval-Print-Loop) or "Interactive Shell" allows you to 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)
Copy after login
Utilizing plugins

In this example we will use the nibStylus plugin to illustrate 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) 
Copy after login

We use stylus(1) to try to render through standard input and output The first thing might look like this:

$ stylus < test.styl
Copy after login

This might generate an error like this 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)
Copy after login

For simple applications of the Stylus API With our plugin, we can add search paths. By using the --include or -I flag:

$ stylus < test.styl --include ../nib/lib
Copy after login

Now the generated content is as follows. You may have noticed that gradient-data-uri() and create-gradient-image() are output in literal form. This is because when a plug-in provides a JavaScript API, it is not enough to expose the plug-in's path. However, if all we want is pure Stylus nib functions, that's enough.

body {  background: url(gradient-data-uri(create-gradient-image(20px, top)));  background: -webkit-gradient(linear, left top, left bottom, 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

So what we need to do is use the --use or -u flag. It will look for the node module (with or without .js extension) path. The require() module here may call style.use(fn()) to expose the plug-in (define js functions, etc.).

$ stylus < test.styl --use ../nib/lib/nib
Copy after login

is generated as:

body {  background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAUCAYAAABMDlehAAAABmJLR0QA/wD/AP+gvaeTAAAAI0lEQVQImWP4+fPnf6bPnz8zMH358oUBwkIjKJBgYGNj+w8Aphk4blt0EcMAAAAASUVORK5CYII=");  background: -webkit-gradient(linear, left top, left bottom, 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

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 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)

How to evaluate the cost-effectiveness of commercial support for Java frameworks How to evaluate the cost-effectiveness of commercial support for Java frameworks Jun 05, 2024 pm 05:25 PM

Evaluating the cost/performance of commercial support for a Java framework involves the following steps: Determine the required level of assurance and service level agreement (SLA) guarantees. The experience and expertise of the research support team. Consider additional services such as upgrades, troubleshooting, and performance optimization. Weigh business support costs against risk mitigation and increased efficiency.

How does the learning curve of PHP frameworks compare to other language frameworks? How does the learning curve of PHP frameworks compare to other language frameworks? Jun 06, 2024 pm 12:41 PM

The learning curve of a PHP framework depends on language proficiency, framework complexity, documentation quality, and community support. The learning curve of PHP frameworks is higher when compared to Python frameworks and lower when compared to Ruby frameworks. Compared to Java frameworks, PHP frameworks have a moderate learning curve but a shorter time to get started.

How do the lightweight options of PHP frameworks affect application performance? How do the lightweight options of PHP frameworks affect application performance? Jun 06, 2024 am 10:53 AM

The lightweight PHP framework improves application performance through small size and low resource consumption. Its features include: small size, fast startup, low memory usage, improved response speed and throughput, and reduced resource consumption. Practical case: SlimFramework creates REST API, only 500KB, high responsiveness and high throughput

Performance comparison of Java frameworks Performance comparison of Java frameworks Jun 04, 2024 pm 03:56 PM

According to benchmarks, for small, high-performance applications, Quarkus (fast startup, low memory) or Micronaut (TechEmpower excellent) are ideal choices. SpringBoot is suitable for large, full-stack applications, but has slightly slower startup times and memory usage.

Golang framework documentation best practices Golang framework documentation best practices Jun 04, 2024 pm 05:00 PM

Writing clear and comprehensive documentation is crucial for the Golang framework. Best practices include following an established documentation style, such as Google's Go Coding Style Guide. Use a clear organizational structure, including headings, subheadings, and lists, and provide navigation. Provides comprehensive and accurate information, including getting started guides, API references, and concepts. Use code examples to illustrate concepts and usage. Keep documentation updated, track changes and document new features. Provide support and community resources such as GitHub issues and forums. Create practical examples, such as API documentation.

How to choose the best golang framework for different application scenarios How to choose the best golang framework for different application scenarios Jun 05, 2024 pm 04:05 PM

Choose the best Go framework based on application scenarios: consider application type, language features, performance requirements, and ecosystem. Common Go frameworks: Gin (Web application), Echo (Web service), Fiber (high throughput), gorm (ORM), fasthttp (speed). Practical case: building REST API (Fiber) and interacting with the database (gorm). Choose a framework: choose fasthttp for key performance, Gin/Echo for flexible web applications, and gorm for database interaction.

Detailed practical explanation of golang framework development: Questions and Answers Detailed practical explanation of golang framework development: Questions and Answers Jun 06, 2024 am 10:57 AM

In Go framework development, common challenges and their solutions are: Error handling: Use the errors package for management, and use middleware to centrally handle errors. Authentication and authorization: Integrate third-party libraries and create custom middleware to check credentials. Concurrency processing: Use goroutines, mutexes, and channels to control resource access. Unit testing: Use gotest packages, mocks, and stubs for isolation, and code coverage tools to ensure sufficiency. Deployment and monitoring: Use Docker containers to package deployments, set up data backups, and track performance and errors with logging and monitoring tools.

What are the common misunderstandings in the learning process of Golang framework? What are the common misunderstandings in the learning process of Golang framework? Jun 05, 2024 pm 09:59 PM

There are five misunderstandings in Go framework learning: over-reliance on the framework and limited flexibility. If you don’t follow the framework conventions, the code will be difficult to maintain. Using outdated libraries can cause security and compatibility issues. Excessive use of packages obfuscates code structure. Ignoring error handling leads to unexpected behavior and crashes.

See all articles