Table of Contents
安装sass,compass
sass的使用及优点
compass的使用
Home Web Front-end HTML Tutorial sass,compass让开发效率飞起_html/css_WEB-ITnose

sass,compass让开发效率飞起_html/css_WEB-ITnose

Jun 24, 2016 am 11:23 AM
sass

最近开始学习并且使用,发现使用它写起css来真的是各种爽

安装sass,compass

  1. sass是依赖于ruby的,必须先安装Ruby,点击下载
  2. 下载完ruby之后,使用命令行安装sass        gem install sass
  3. 使用命令,sass-v    compass-v   查看是否安装成功

   

   出现上图情况则为安装成功

 

sass的使用及优点

  • sass官网: http://www.w3cplus.com/sassguide/
  • sass功能:
  • 定义变量,数值计算(左边为scss文件,右边为编译之后的css文件)

    方便知道谁是谁的子元素,不必写一大堆重复的标签

    还可以像函数一样使用,可以传参数,可以设置默认参数

    这还远远不够,如果sass不和compass一起使用,很难体现它功能的强大性

    compass的使用

    1.官方文档 http://compass-style.org/help/tutorials/production-css/

    2.compass的特性

  • 轻松实现浏览器兼容
  • 全面支持css3
  • 提供海量使用功能,颜色处理,获取客户端数据等
  • 轻松实现扩展
  • 3.常用功能:

     1.@import(合并css文件,实现模块化)

    可以将项目中的各部分样式拆分成 _head.scss,_body.scss,_foot.scss    (注意!要以_开头,这样子这些文件便不会被编译成css文件)

    实现效果

    使用方法,在main.scss中,加入以下代码

    1 @import "base/head";2 @import "base/body"; 3 @import "base/foot";
    Copy after login

    执行编译,即可实现

    2.css3兼容性

    无需每次都重复写多个浏览器前缀,只需在前面写上 @include (这里用正常的css3方式写)

    3.合并雪碧图

    说明:CSS雪碧图是将几个图片拼合成一张图片,以此来减少HTTP请求的方法,并且可以提升网站加载速度

    目录结构如下:share目录下放未经合并的图片,在images目录下的图片即为合并之后的图片

    使用方法:

    在share.scss中输入以下3行代码

    1 @import "compass/utilities/sprites";   2 @import "share/*.png";       //注意这里的路径,*表示匹配所有png格式的图片3 @include all-share-sprites;   //中间的share为存放未合并文件的目录名字,
    Copy after login

    再执行编译即可,效果图如下,随便测试的,有点丑嘿嘿

    并且,在share.css文件中,还将图片的位置都计算好了,使用起来非常的方便,如下

    出现过的bug:

    1 error sass/screen.sccc (c:/Ruby22-x64/lib/ruby/gems/2.2.0/compass-1.0.3/lib/compass/sass_extensions/functions/sprite.rb:137:in 'sprite_does_not_have_parent':undefined 'parent' for nil:NilClass)
    Copy after login

    解决方法: 图片名字,不要有数字,中文之类的

    4.浏览器Normalize.css(解决各种浏览器样式不统一的问题)

    (1)说明:Normalize.css是一种CSS reset的替代方案。

    (2)优点:

  • 保护有用的浏览器默认样式而不是完全去掉它们
  • 一般化的样式:为大部分HTML元素提供
  • 修复浏览器自身的bug并保证各浏览器的一致性
  • 优化CSS可用性:用一些小技巧
  • 解释代码:用注释和详细的文档来
  • (3)官方文档 https://github.com/ksmandersen/compass-normalize

    (4)安装 gem install compass-normalize

    (5)使用方法

  • 新创建一个项目
  • compass create -r compass-normalize --using compass-normalize

  • 在已经存在的项目添加
  • 在config.rb 中添加 require'compass-normalize'

  • 使用规范化的插件,只需要引入 @import "normalize"; //这个为全部引入
  •  正常情况下是选择需要的模块,单独引入,防止代码冗余,如下

    1 @import 'normalize/html5';2 @import 'normalize/base';3 @import 'normalize/links';4 @import 'normalize/typography';5 @import 'normalize/embeds';6 @import 'normalize/groups';7 @import 'normalize/forms';8 @import 'normalize/tables';
    Copy after login

    scss编译,compass编译

     说了这么多,还差编译

    1.使用可视化工具编译      例如:koala   (实时编译,可压缩,支持多语言,使用简单)

    下载地址,点击下载

    2.使用命令行

    创建一个工程       compass create myproject  点击进入创建的目录,出现以下3个文件

     编译        compass compile   (在项目根目录下使用,将sass目录中的文件编译成css,css的路径为在config.rb配置的css-dir)

    常用命令行如下

    3.使用前端自动化工具 gulp  

    (接下来会写一篇gulp的文章,未完待续)

    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)

    Hot Topics

    Java Tutorial
    1659
    14
    PHP Tutorial
    1257
    29
    C# Tutorial
    1231
    24
    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.

    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.

    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.

    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.

    HTML: The Structure, CSS: The Style, JavaScript: The Behavior HTML: The Structure, CSS: The Style, JavaScript: The Behavior Apr 18, 2025 am 12:09 AM

    The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

    The Future of HTML: Evolution and Trends in Web Design The Future of HTML: Evolution and Trends in Web Design Apr 17, 2025 am 12:12 AM

    The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

    The Future of HTML, CSS, and JavaScript: Web Development Trends The Future of HTML, CSS, and JavaScript: Web Development Trends Apr 19, 2025 am 12:02 AM

    The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

    See all articles