Home Web Front-end HTML Tutorial Sass基础语法_html/css_WEB-ITnose

Sass基础语法_html/css_WEB-ITnose

Jun 24, 2016 am 11:18 AM

Sass是CSS3语言的扩展,在CSS的基础之上添加了新特性和语法,能省事地写出更好的样式表。Sass引擎是基于Ruby的。

导入Sass文件:

@import "colors" //colors.scss
Copy after login

注释:

//这种注释不会出现在生成的css文件中/*这种注释内容会出现在css文件中,当当出现在原生CSS不允许的未知,则这些注释会被抹掉*/
Copy after login

变量>>

-->变量声明 

//注意:变量中下划线和中划线表示同一个变量<br />$flower-color:#abcdef;      //flower-color是一个变量,其值现在是#abcdef$basic-border:1px solid black;    //任何可以用作CSS属性值的赋值都可以作为SASS的变量值$basic-font:"MyriadPro"、Myriad、"helveticaNuue"、Helvetica;//也可以是逗号分割的多个属性值//与CSS属性不同,变量可以在CSS会泽块定义之外使用。当变量定义在CSS规则块内,那么该变量只能在其子级规则块内使用。<br />$nav-color:#dadada;nav{    $width:100px;    width:$width;    color:$nav-color;}
Copy after login

-->变量引用

凡是CSS属性的标准值可以存在的地方,变量就可以实用。

$flower-color:red; //变量声明.flower{ //变量引用      border:1px $flower-color solid;}
Copy after login

嵌套规则>>

-->基本嵌套规则,和一些编程语言很类似很容易理解,群则选择器的嵌套也和CSS语法一样

//CSS 代码,经常重复写选择器#content article h1{color:#333}#contetn article p{margin-bottom:1.5em;}#cojntent aside{background-color:#eee;}//SASS代码,选择器嵌套#content{    article{        h1{color:#333}        p{margin-bottom:1.5em}    }    aside{background-color:#eee;}}
Copy after login

-->父选择器的标识符&

article a{    color:blue;    &:hover{color:red}    //必须标识父选择器&,否则SASS无法正常工作}//CSS 代码article a{color:blue}article a:hover{color:red}
Copy after login

-->子组合选择器和同层组合选择器:> + ~

这些选择器必须配合其他选择器实用,以制定浏览器仅选择某种特定上下文中的元素。这些选择器可以应用带Sass的规则嵌套中。

article section{margin:5px;}//用子组合选择器>选择一个元素的直接子元素article>section{border:1px red solid}
Copy after login

//同层相邻组合选择器+选择元素紧跟着的元素header + p {font-size:1.1em}
Copy after login

//同层全体组合选择齐齐~,选择跟在元素后的同层元素,不管他们之间间隔了多少其他元素article ~ article {border:1px solid red;}
Copy after login

-->嵌套属性

除了选择器,属性也可以进行嵌套。

nav{    border:1px solid #ccc{        left:0px;        right:0px;    }}
Copy after login

虽然属性和选择器嵌套可以大大减少便血量,但当样式表越来越大,这种写法很难保持结构清晰。而处理大量样式的唯一方法就是分拆成多个文件。

混合器>>

@mixin corners{ //用@mixin标识符定义    -moz-border-radius:5px;    -ms-border-radius:5px;    -webkit-border-radius:5px;;    -o-border-radius:5px;    border-radius:5px;}.calamus{    border:2px solid red;    @include corners;       //用@include调用混合器中的所有样式}//混合器中不仅可以包含css规则还可以包含属性,也可以嵌套//混合器可以传递参数@maxin link-colors($normal,$hover){    color:$normal;    &:hover{color:$hover}}a{    @include link-colors(blue,red);  //参数的传递}
Copy after login

继承>>

通过 @extend实现

.error{    border:1px solid red;    color:red;}.seriousError{    @extend .error;      //继承error的属性值   width:300px;}
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

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)

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

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.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

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.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

How to implement adaptive layout of Y-axis position in web annotation? How to implement adaptive layout of Y-axis position in web annotation? Apr 04, 2025 pm 11:30 PM

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

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.

How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? Apr 05, 2025 am 06:15 AM

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

See all articles