Home Web Front-end CSS Tutorial Sass vs. Compass – Review

Sass vs. Compass – Review

Feb 13, 2017 pm 02:52 PM

compass is a tool library for sass
compass encapsulates a series of useful modules based on sass to supplement and enrich the functionality of sass.

Installation:
compass is It is developed in ruby ​​language, so ruby ​​must be installed before installing it.
Command:

gem install compass
Project initialization:
To create your Compass project, if the name of the project is myproject
compass create myproject
will be in the current This directory is generated under the directory, which contains the config.rb file, and two subdirectories, sass and stylesheets. The former stores sass source files, and the latter stores compiled
css files.

Compilation:
When I was developing, I wrote a file with the file suffix scss. Only when compiled into css files can they be used on the website. The compilation command of
compass is
compass compile
This command is run in the project root directory and will compile the scss file in the sass subdirectory into a css file and save it in the stylesheets subdirectory.
The css file compiled by default has a large number of comments. The production environment requires compressed css files
compass compile --output-style compressed
If you recompile the unmodified file
compass compile --force
In addition to using command parameters, you can also specify the compilation mode in the configuration file config.rb.

output_style = :expanded
:expanded means retaining the original format after compilation. Other values ​​include: nested,
:compact and compressed. After entering the production stage, it must be changed to :compressed mode.
output_style = :compressed
You can also intelligently determine the compilation mode by specifying the environment value (:production or:development).

environment = :development
output_style = (environment == :production) ? :compressed : :expanded

In command line mode, in addition to one-time compilation commands, compass also has automatic Compilation command

compass watch
As long as the scss file changes, it will be automatically compiled into a css file.

compass’s module

compass adopts a module structure. Different modules provide different functions, and there are 5 built-in modules.
reset css3 layout typography unilities

reset module

Before writing your own styles, it is necessary to reset the browser's default styles.
The writing method is:
@import "compass/reset"
The above @import command is used to specify the loading module, here it is to load the reset module. After compilation, the corresponding css reset code will be generated.

CSS3 module
This module provides 24 css3 commands. For example:
The way to write rounded corners (border-radius),
@import "compass/css3";
.rounded {
@include border-radius(5px);
 }
The @include command above means calling a mixin (similar to a macro in C language). 5px is a parameter, which is used to specify the radius of the fillet.

The compiled code is:
.rounded {
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-o-border- radius: 5px;
-ms-border-radius: 5px;
-khtml-border-radius: 5px;
border-radius: 5px;
}

If you only need The upper left corner is rounded, written as
@include border-corner-radius(top, left, 5px);

layout module
This module provides layout functions,
For example, specify the page The footer section appears at the bottom of the browser.
@import "compass/layout";
#footer {
@include sticky-footer(54px);
}
Specifies that the child element takes up the space of the parent element:

@import "compass/layout";
#stretch-full {
@include stretch;
}
typography module
This module provides template functions
For example, specify the link color The mixin is:
link-colors($normal, $hover, $active, $visited, $focus);
When used, it is written as:
@import "compass/typography";
a {
 @include link-colors(#00c, #0cc, #c0c, #ccc, #cc0);
}

utilities module

This module provides some functions of other modules.
For example, clear floating:

import "compass/utilities/";
.clearfix {
@include clearfix;
 }
For example, table:
@import "compass/utilities";
table {
@include table-scaffolding;
 }

After compilation
table th {
text-align: center;
font-weight: bold;
}
table td,
table th {
padding: 2px;
}
table td.numeric,
table th.numeric {
text-align: right;
}

Helper function
In addition to modules, compass also provides a series of functions.
There are some useful functions, image-width() and image-height() return the width and height of the image
Another example, inline-image() can convert the image into data protocol data.

@import "compass";
.icon { background-image: inline-image("icon.png");}

After compilation, we get
.icon { background -image: url('data:image/png;base64,iBROR...QmCC');}
The main difference between function and mixin is that there is no need to use the @include command and can be called directly.

For more Sass and Compass - to review related articles, please pay attention to 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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Building an Ethereum app using Redwood.js and Fauna Building an Ethereum app using Redwood.js and Fauna Mar 28, 2025 am 09:18 AM

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Let's use (X, X, X, X) for talking about specificity Let's use (X, X, X, X) for talking about specificity Mar 24, 2025 am 10:37 AM

I was just chatting with Eric Meyer the other day and I remembered an Eric Meyer story from my formative years. I wrote a blog post about CSS specificity, and

See all articles