search
HomeWeb Front-endCSS TutorialSass 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
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
A Little Reminder That Pseudo Elements are Children, Kinda.A Little Reminder That Pseudo Elements are Children, Kinda.Apr 19, 2025 am 11:39 AM

Here's a container with some child elements:

Menus with 'Dynamic Hit Areas'Menus with 'Dynamic Hit Areas'Apr 19, 2025 am 11:37 AM

Flyout menus! The second you need to implement a menu that uses a hover event to display more menu items, you're in tricky territory. For one, they should

Improving Video Accessibility with WebVTTImproving Video Accessibility with WebVTTApr 19, 2025 am 11:27 AM

"The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect."- Tim Berners-Lee

Weekly Platform News: CSS ::marker pseudo-element, pre-rendering web components, adding Webmention to your siteWeekly Platform News: CSS ::marker pseudo-element, pre-rendering web components, adding Webmention to your siteApr 19, 2025 am 11:25 AM

In this week's roundup: datepickers are giving keyboard users headaches, a new web component compiler that helps fight FOUC, we finally get our hands on styling list item markers, and four steps to getting webmentions on your site.

Making width and flexible items play nice togetherMaking width and flexible items play nice togetherApr 19, 2025 am 11:23 AM

The short answer: flex-shrink and flex-basis are probably what you’re lookin’ for.

Position Sticky and Table HeadersPosition Sticky and Table HeadersApr 19, 2025 am 11:21 AM

You can't position: sticky; a

Weekly Platform News: HTML Inspection in Search Console, Global Scope of Scripts, Babel env Adds defaults QueryWeekly Platform News: HTML Inspection in Search Console, Global Scope of Scripts, Babel env Adds defaults QueryApr 19, 2025 am 11:18 AM

In this week's look around the world of web platform news, Google Search Console makes it easier to view crawled markup, we learn that custom properties

IndieWeb and WebmentionsIndieWeb and WebmentionsApr 19, 2025 am 11:16 AM

The IndieWeb is a thing! They've got a conference coming up and everything. The New Yorker is even writing about it:

See all articles

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

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool