


Author of the article: Songyang
Why Scss
CSS is not a programming language, It is just a configuration file and has no life. But how can I, a large program, tolerate that the things I write cannot change dynamically, cannot be encapsulated and inherited, and cannot be xxoo, so the concept of CSS preprocessing came into being. That is, writing is one thing and using it is another thing. Scss is an option for css preprocessing. It relies on Ruby and is relatively high-quality. Similar ones include Less and so on. The debate about the quality of languages is of little significance. It is similar to using one of the others well.
Installation
Ruby comes with Mac, just run:
gem install sass
to install the corresponding module, and then you can use:
sass --watch style.scss:style.css
command Monitor style.scss and automatically compile it into style.css when it changes.
Friendly reminder: When I ran the gem, it didn’t move at all. I thought it was disconnected. Later I heard that it was because of my great GFW power that I could change the source to xbao’s server to solve the problem:
$ gem sources -l$ gem sources --remove https://rubygems.org/ $ gem sources -a http://ruby.taobao.org/$ gem sources -l//然后我顺手更新了一下Ruby的版本$ sudo gem update --system
After the above troubles, sass was successfully installed
Common syntax
Variables
//定义$magin : 30px; //px$blue : #1875e7; //color$side : left; //str Usage: boder-#{$side}-radius
All numeric type variables can be calculated accordingly.
Nested
nav { ul {...} border : { //注意冒号 相当于树形属性 会编译成 border-color:red color : red; } a { &:hover { color :$blue;} //&表示引用上层 会编译成 a:hover{...} }}
Comments
Standard CSS comments /* comment */ will be retained in the compiled file.
Single-line comment // comment, only retained in the SASS source file, will be omitted after compilation.
Add an exclamation mark after /* to indicate that this is an "important comment". Even when compiling in compressed mode, this line of comments will be retained and can usually be used to declare copyright information.
Inherit
Use @extend to inherit the corresponding css:
.class1 { border:1px solid #ddd;}.class2 { @extend .class1; border-color: green;}
Pay attention to the order when writing. When compiling, the css will not adjust the order. Who You have to decide which one comes first.
Mixin
This is the illegitimate child of a function and a macro. To implement like functions, use like macros. The keywords are @mixin and @include
@mixin left($color, $value:10px) { color:$color; margin-left:$value;}.mydiv { @include left($blue,15px);}
Color processing function
lighten(#cc3, 10%) // #d6d65cdarken(#cc3, 10%) // #a3a329grayscale(#cc3) // #808080complement(#cc3) // #33c$linkColor: #08c;a { text-decoration:none; color:$linkColor; &:hover{ color:darken($linkColor,10%); }}
Using this method to create a link graying effect
Introduction file
@import "style2.css";
Logic compilation
If you want to really move it, you have to make judgments and loop through regular process functions.
@if can be used alone as a condition, or can be used in combination with @else for multiple conditions
$type: monster;p { @if $type == ocean { color: blue; } @else if $type == matador { color: red; } @else if $type == monster { color: green; } @else { color: black; }}
The for loop has two forms, namely: @for $var from
@for $i from 1 through 3 { .item-#{$i} { width: 2em * $i; }}
The syntax of each is: @each $var in . Among them, $var represents variables, while list and map represent list type data and map type data.
$animal-list: puma, sea-slug, egret, salamander;@each $animal in $animal-list { .#{$animal}-icon { background-image: url('/images/#{$animal}.png'); }}$headings: (h1: 2em, h2: 1.5em, h3: 1.2em);@each $header, $size in $headings { #{$header} { font-size: $size; }}
sublime paging
Actually, this is not considered Scss knowledge, but it is just more convenient to use it. Sublime can split the screen left and right. We can put the source file in the window on the left and the compiled one on the right to facilitate our inspection. The shortcut keys on Mac are quite perverted:
cmd+option+ctrl+2
Use to move left and right
cmd+shift+[
If you think this article is helpful to you, you can give it a like, not only I won’t be happy to be a father, but I can also let more people see it...

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

How to design the dotted line segmentation effect in the menu? When designing menus, it is usually not difficult to align left and right between the dish name and price, but how about the dotted line or point in the middle...

HTML Element Analysis in Web Code Editor Many online code editors allow users to enter HTML, CSS, and JavaScript code. Recently, someone proposed...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use