SASS & LESS Syntactically Awesome StyleSheets Dynamic StyleSheet Language Svetlin Nakov Technical Trainer Software University

Slides:



Advertisements
Similar presentations
CSS Typography, Fonts, Spacing, Borders, Backgrounds, Opacity
Advertisements

JavaScript Basics Course Introduction SoftUni Team Technical Trainers Software University
Software Quality Assurance QA Engineering, Testing, Bug Tracking, Test Automation Software University Technical Trainers SoftUni Team.
AngularJS Routing Routes, Route Parameters, Templates, Location, Navigation SoftUni Team Technical Trainers Software University
AngularJS Services Built-in and Custom Services SoftUni Team Technical Trainers Software University
Software University Curriculum, Courses, Exams, Jobs SoftUni Team Technical Trainers Software University
Fundamentals SoftUni Welcome to Software University SoftUni Team Technical Trainers Software University
Advanced JavaScript Course Introduction SoftUni Team Technical Trainers Software University
Project Tracking Tools Trello, Asana, Basecamp, GitHub Issue Tracker, TRAC SoftUni Team Technical Trainers Software University
AngularJS Directives Defining Custom Directives SoftUni Team Technical Trainers Software University
Software Testing Lifecycle Exit Criteria Evaluation, Continuous Integration Ivan Yonkov Technical Trainer Software University.
Fundamentals SoftUni Welcome to Software University SoftUni Team Technical Trainers Software University
Svetlin Nakov Technical Trainer Software University
Build Processes and Continuous Integration Automating Build Processes Software University Technical Trainers SoftUni Team.
Lesson 03 // Cascading Style Sheets. CSS Stands for Cascading Style Sheets. We’ll be using a combination of Html and CSS to create websites. CSS is a.
Processing Redis with.NET How to Operate with Redis Databases SoftUni Team Technical Trainers Software University
Project Tracking Tools Trello, Asana, Basecamp, GitHub Issue Tracker, TRAC Angel Georgiev Part-time Trainer Software University
Test-Driven Development Learn the "Test First" Approach to Coding SoftUni Team Technical Trainers Software University
JavaScript Basics Course Introduction Svetlin Nakov Technical Trainer Software University
CSS Layout Arrangement and Positioning of the HTML Elements Svetlin Nakov Technical Trainer Software University
Advanced Web Development Instructor: Thomas Bombach.
Templating, Routing, lodash Extending functionality using Collections SoftUni Team Technical Trainers Software University
Controllers and Markup Controllers, $scope, Markup, Directives, Expressions, Binding, Filters, Validation SoftUni Team Technical Trainers Software University.
AMD and RequireJS Splitting JavaScript Code into Dependent Modules Software University Technical Trainers SoftUni Team.
Asynchronous Web Services Writing Asynchronous Web Services SoftUni Team Technical Trainers Software University
C# Basics Course Introduction Svetlin Nakov Technical Trainer Software University
CSS Presentation CSS Typography, Fonts, Spacing, Borders, Backgrounds, Opacity Svetlin Nakov Technical Trainer Software University
Web Fundamentals (HTML and CSS) Course Introduction SoftUni Team Technical Trainers Software University
Controls, Widgets, Grid…
HTML – Other Tags Semantic Tags, Frames, Embed Multimedia Content, Others SoftUni Team Technical Trainers Software University
Jekyll Static Site Generator Template-Based Site Generation Svetlin Nakov Technical Trainer Software University
Web Fundamentals (HTML and CSS) Course Introduction Svetlin Nakov Technical Trainer Software University
Forms Overview, Query string, Submitting arrays, PHP & HTML, Input types, Redirecting the user Mario Peshev Technical Trainer Software.
Web Development Tools Tools for Front-End Developers Writing HTML and CSS Code SoftUni Team Technical Trainers Software University
HTML 5 Overview Document Structure, Basic Tags, Common Elements SoftUni Team Technical Trainers Software University
Web Fundamentals (HTML and CSS)
JQuery Overview Unleash the Power of jQuery SoftUni Team Technical Trainers Software University
Responsive Design Design that Adapts to Different Devices SoftUni Team Technical Trainers Software University
Tables, Rows, Columns, Cells, Header, Footer, Colspan, Rowspan
 HTML, CSS, JavaScript – enormously successful  SASS has all the tools we need! INTRO.
CSS Transitions and Animations Animated HTML Elements SoftUni Team Technical Trainers Software University
High-Quality Code: Course Introduction Course Introduction SoftUni Team Technical Trainers Software University
Design Patterns: Structural Design Patterns General and reusable solutions to common problems in software design Software University
Bootstrap Front-End Framework for Responsive Web Sites Svetlin Nakov Technical Trainer Software University
Advanced C# Course Introduction SoftUni Team Technical Trainers Software University
Object-Oriented Programming Course Introduction Svetlin Nakov Technical Trainer Software University
JavaScript Applications Course Introduction SoftUni Team Technical Trainers Software University
Mocking with Moq Tools for Easier Unit Testing SoftUni Team Technical Trainers Software University
Mocking with Moq Mocking tools for easier unit testing Svetlin Nakov Technical Trainer Software University
JavaScript Tools Tools for Writing / Editing / Debugging JavaScript Code Svetlin Nakov Technical Trainer Software University
Test-Driven Development Learn the "Test First" Approach to Coding Svetlin Nakov Technical Trainer Software University
Programming for Beginners Course Introduction SoftUni Team Technical Trainers Software University
Sets, Dictionaries SoftUni Team Technical Trainers Software University
JavaScript Applications Course Introduction SoftUni Team Technical Trainers Software University
Creating Content Defining Topic, Creating Technical Training Materials SoftUni Team Technical Trainers Software University
High-Quality Code: Course Introduction Course Introduction SoftUni Team Technical Trainers Software University
PHP Basics Course Introduction Svetlin Nakov Technical Trainer Software University
Software Technologies Course Overview SoftUni Team Technical Trainers Software University
Programming Fundamentals Course Introduction SoftUni Team Technical Trainers Software University
Doctrine The PHP ORM SoftUni Team Technical Trainers Software University
Creating Content Defining Topic, Creating Technical Training Materials SoftUni Team Technical Trainers Software University
ASP.NET MVC Course Program, Trainers, Evaluation, Exams, Resources SoftUni Team Technical Trainers Software University
First Steps in PHP Creating Very Simple PHP Scripts SoftUni Team Technical Trainers Software University
Inheritance Class Hierarchies SoftUni Team Technical Trainers Software University
Doing More with Less for CSS Todd Anglin Telerik
Advanced JavaScript Course Introduction SoftUni Team Technical Trainers Software University
Stacks and Queues Processing Sequences of Elements SoftUni Team Technical Trainers Software University
Extending functionality using Collections
CSS Transitions and Animations
CSS Transitions and Animations
Presentation transcript:

SASS & LESS Syntactically Awesome StyleSheets Dynamic StyleSheet Language Svetlin Nakov Technical Trainer Software University

2  SASS Overview  Working with SASS  Using the Visual Studio Plugins  SASS Features  Nesting  Variables  Mixins  Selector Inheritance  LESS Overview Table of Contents

SASS Overview

4  Syntactically Awesome Stylesheets (SASS)  Extension of CSS  Makes CSS coding much easier and organized  Translates to pure CSS (server-side)  No slowdown at the client  SASS powers the CSS coding through  Variables (define once, use at many places)  Mixins (reusable functions with parameters) SASS

5  SASS has many implementations (  Usually available directly in your IDE as a plugin  Originally SASS was a Ruby-based tool 1. Install Ruby (e.g. from 2. Install the "SASS" gem module ( gem install sass )  SASS is natively supported in Visual Studio (from 2013 U2)  Web Essentials is recommended for better support  SASS Tools

Coding SASS in Visual Studio Live Demo

SASS Features

8 SASS Selector Nesting body { font: normal 16px arial; font: normal 16px arial; color: #fff; color: #fff; background-color: #011b63; background-color: #011b63; div { div { font-size: 2.3em; font-size: 2.3em; font-weight: bold; font-weight: bold; ul li { ul li { list-style-type:none; list-style-type:none; a { a { text-decoration:none; text-decoration:none; color:white; color:white; } } }} body { font: normal 16px arial; font: normal 16px arial; color: #fff; color: #fff; background-color: #011b63; background-color: #011b63;} body div { font-size: 2.3em; font-size: 2.3em; font-weight: bold; font-weight: bold;} body div ul li { list-style-type: none; list-style-type: none;} body div ul li a { text-decoration: none; text-decoration: none; color: white; color: white;} SASSCompile

9  Selectors can also reference themselves by the & symbol: SASS Selector Nesting body { font: normal 16px arial; font: normal 16px arial; color: #fff; color: #fff; background-color: #011b63; background-color: #011b63; a { a { text-decoration:none; text-decoration:none; color:white; color:white; &:hover { &:hover { text-decoration:underline; text-decoration:underline; color:tomato; color:tomato; } }} body { font: normal 16px arial; font: normal 16px arial; color: #fff; color: #fff; background-color: #011b63; background-color: #011b63;} body a { text-decoration: none; text-decoration: none; color: white; color: white;} body a:hover { text-decoration: underline; text-decoration: underline; color: tomato; color: tomato;} SASSCompile

Selector Nesting in SASS Live Demo

11  SASS supports variables  Using the $ (dollar) symbol  E.g. $text-color, $font-size  Variables have name and hold value  Can be defined outside the selector, always up!  Can be used to store colors, size, etc…  Usable to set one element many times (“code reuse”) SASS Variables $text-color: tomato;

12 SASS Variables – Example $color-non-visited: black; $color-visited: tomato; body { a { a { color: $color-non-visited; color: $color-non-visited; &:visited { &:visited { color: $color-visited; color: $color-visited; } }} body a { color: black; color: black;} body a:visited { color: tomato; color: tomato;} SASSCompile

13  SASS variables can be inserted as CSS properties  Using #{$variable} SASS Variables-Interpolation $border-side: top; $border-color: tomato; $border-style: ridge; $border-width: 15px; li { border-#{$border-side}: border-#{$border-side}: $border-width $border-style $border-color; $border-width $border-style $border-color;} border-top: 15px ridge tomato;

SASS Variables Live Demo

Mixins

16  Mixins are kind of developer-defined functions  Allow reusing blocks of code several times  Two kind of mixins  Parameterless  Render the same styles every time  With parameters  Render styles based on some input parameters  E.g. gradients, borders, etc… Mixins: Reusable Blocks of SASS Code

17  Defining a mixin (without parameters):  Using (including) a mixin: Defining and Using default-element-border { border: 1px solid black; border: 1px solid black; background: tomato; background: tomato; border-radius: 10px; border-radius: 10px;} ul li default-element-border;}

18  Mixins can also be defined with parameters  Defined like in C# / Java / JS and can have default value Mixins with opacity-maker($value) { opacity: $value; filter: alpha(opacity=($value*100)); zoom: 1; box-initialize($border:none,$background:rgba(0,0,0,0.7),$size:200px) { width: $size; height: $size; border: $border; background: $background; padding: 15px; }

SASS Mixins Live Demo

20  We can inherit selectors in SASS SASS Selector Inheritance.default-border { border: 3px solid black; border: 3px solid black; background: tomato; background: tomato; border-radius: 8px; border-radius: border-style: dotted; border-style: dotted;}.default-border,.dotted-border { border: 3px solid black; border: 3px solid black; background: tomato; background: tomato; border-radius: 8px; border-radius: 8px;}.dotted-border { border-style: dotted; border-style: dotted;} SASSCompile

Selector Inheritance Live Demo

 SASS files can be imported in other SASS files  Like CSS files can be imported in CSS  Use directive  SASS defines partials  i.e. SASS files that are meant to be imported  Just use prefix _ (underscope) Importing SASS '_gradients.scss' // and can use the items from _gradients.scss

Import SASS files Live Demo

LESS

 LESS is CSS preprocessor, similar to SASS   Can be compiled both in the browser at the server  Using a LESS parser written in JavaScript  LESS features include  Nesting selectors  Variables  Mixins  Color editing functions LESS

26 LESS – @base { color: #888 / 4; color: #888 / 4; + #111; + #111; height: 100% / 2 height: 100% / 2 { color: #222222; color: #222222; background-color: #119111; background-color: #119111; height: 60%; height: 60%;} LESSCompile

27  LESS can be compiled at the client-side (in the Web browser):  Using the JavaScript preprocessor less.js  Note: client-side LESS compilation slows-down your site!  If using Visual Studio, you should add a MIME type for the LESS in your site's Web.config (otherwise.less files can't be served) Using LESS at the Client //after the less link //after the less link

28  LESS can be compiled on the server  Using the client approach and copy the CSS  Not good enough, lots of copy-pastying  Using Node.js to do the parsing  Better solution – the parsing is automated  Using plugins for your favorite Web editor  Web Essentials for Visual Studio (or Visual Studio 2003 U2+)  LESS and LESS2CSS for Sublime Text Parsing LESS on the Server

29  SASS  Simplifies the CSS development + enables code reuse  SASS support in Visual Studio  Use VS 2013U2 (or later) + Web Essentials  SASS features  Nesting, variables, mixins, inheritance  LESS  Similar to SASS, can be processed client-side Summary

? ? ? ? ? ? ? ? ? SASS & LESS

License  This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International" licenseCreative Commons Attribution- NonCommercial-ShareAlike 4.0 International 31  Attribution: this work may contain portions from  "HTML Basics" course by Telerik Academy under CC-BY-NC-SA licenseHTML BasicsCC-BY-NC-SA  "CSS Styling" course by Telerik Academy under CC-BY-NC-SA licenseCSS StylingCC-BY-NC-SA

Free Software University  Software University Foundation – softuni.orgsoftuni.org  Software University – High-Quality Education, Profession and Job for Software Developers  softuni.bg softuni.bg  Software Facebook  facebook.com/SoftwareUniversity facebook.com/SoftwareUniversity  Software YouTube  youtube.com/SoftwareUniversity youtube.com/SoftwareUniversity  Software University Forums – forum.softuni.bgforum.softuni.bg