Using LESS for more maintainable, semantic, and lean web sites Keith Zantow.

Slides:



Advertisements
Similar presentations
Intro To Cascading Style Sheets By Mario Yannakakis.
Advertisements

CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
Cascading Style Sheets
XHTML Basics.
AJAX & By – Anupama Sharma. Defining Ajax Ajax isn’t a technology. It’s really several technologies, each flourishing in its own right, coming together.
DT228/3 Web Development JSP: Directives and Scripting elements.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
Responsive Web Design Nuts & Bolts David Weedon - UI/UX Designer, Covenant Technology Partners.
Bones – HTML5 Wordpress Theme Development
Definition from Wikipedia.  The Prototype JavaScript Framework  implemented as a single file of JavaScript code  named prototype.js (
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
ITM352 PHP and Dynamic Web Pages: Server Side Processing.
Server- Side technologies Client-side vs. Server-side scripts PHP basic ASP.NET basic ColdFusion.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
XML introduction to Ahmed I. Deeb Dr. Anwar Mousa  presenter  instructor University Of Palestine-2009.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Review IDIA 619 Spring 2013 Bridget M. Blodgett. HTML A basic HTML document looks like this: Sample page Sample page This is a simple sample. HTML user.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Introduction To CSS.. HTML Review What is HTML used for? Give some examples of formatting tags in HTML? HTML is the most widely used language on the Web.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
XML A web enabled data description language 4/22/2001 By Mark Lawson & Edward Ryan L’Herault.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Mobile web Sebastian Lopienski IT Technical Forum 29 June 2012.
Selenium and Selenium on Rails. Agenda  Overview of Selenium Simple Selenium Tests Selenium IDE  Overview of Selenium on Rails  Problems with Selenium.
CSS BEST PRACTICES.
Chapter 4: Working with ASP.NET Server Controls OUTLINE  What ASP.NET Server Controls are  How the ASP.NET run time processes the server controls on.
CSS PREPROCESSORS Michael and Miles. Overview What are CSS Preprocessors Why use them? What is LESS and how to use LESS example What is SASS and how to.
JQuery Introduction © Copyright 2014, Fred McClurg All Rights Reserved.
Crazy New CSS Tools MIS 424 MIS 424 Professor Sandvig Professor Sandvig.
SASS & LESS Syntactically Awesome StyleSheets Dynamic StyleSheet Language Svetlin Nakov Technical Trainer Software University
1 CSS-PREPROCESSORS as a way to speed up the process of interfaces developing and achieve Customer goals DMITRY SHURSHILIN AUGUST 3, 2015.
ASP.NET in Definition: 1.ASP.NET is a web application framework developed and marketed by Microsoft to allow programmers to build dynamic web sites,
Introduction to CSS. Why CSS? CSS Provides Efficiency in Design and Updates CSS relatively easy to use Can give you more flexibility and control Faster.
Advanced Topics Lecture 8 Rachel A Ober
Microsoft Expression Web 3 – Illustrated Unit D: Structuring and Styling Text.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Martin Kruliš by Martin Kruliš (v1.0)1.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
LECTURE #4: JQUERY AND FORM VALIDATION Josh Kaine Josh Kaine 4/1/2016.
Getting Started with Angular 2 and TypeScript Nebraska.Code() 2016 Spencer Schneidenbach Ryvit.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
A S P. Outline  The introduction of ASP  Why we choose ASP  How ASP works  Basic syntax rule of ASP  ASP’S object model  Limitations of ASP  Summary.
Javascript Prof. Wenwen Li School of Geographical Sciences and Urban Planning 5644 Coor Hall
Britt BodinNatalie Thomson. AGENDA I. The Problems with CSS II. Introducing Preprocessors III. How They Work IV. It’s Magic. V. Advantages & Disadvantages.
Enhance Your Page Load Speed And Improve Traffic.
Doing More with Less for CSS Todd Anglin Telerik
Introduction To CSS. Lesson 1: History of CSS CSS was proposed in 1994 as a web styling language. To helps solve some of the problems HTML 4. There were.
CSCI 1720 W3.CSS – Part 1 East Tennessee State University Department of Computing CSCI 1720 Intermediate Web Design.
Simple theme creation using Sass
Selenium and Selenium on Rails
ITM352 PHP and Dynamic Web Pages: Server Side Processing 1.
Brian Leonard ブライアン レオナルド
THEAMING WITH SASS Bringing sassy to CSS SITRA.
Tutorial 6 Topic: jQuery and jQuery Mobile Li Xu
Introduction to Web programming
CSS BEST PRACTICES.
SharePoint-Hosted Apps and JavaScript
JavaScript an introduction.
What are Cascading Stylesheets (CSS)?
Tutorial 6 PHP & MySQL Li Xu
JavaScript CS 4640 Programming Languages for Web Applications
Session IV Chapter 20 - How to use SASS and Less
Web Client Side Technologies Raneem Qaddoura
Bootstrap Direct quote from source: bootstrap/
Presentation transcript:

Using LESS for more maintainable, semantic, and lean web sites Keith Zantow

Outline Introduction to LESS Tools and usage Features in detail Enabling leaner HTML

What is LESS? “The dynamic stylesheet language”… huh? Most popular CSS preprocessor Based on CSS Compiles to CSS Server-side & client-side Adds sorely needed maintainability features lesscss.org Developed by Alexis Sellier (cloudhead)Alexis Selliercloudhead

Why use LESS? Code reuse (DRY) More maintainable Easier to read – the structure more closely resembles corresponding HTML Superset of CSS – low barrier of entry Better browser compatibility Written in JavaScript – portable! You’re a hipster Fun! No, really, it is – it’s what CSS should be!

Pitfalls No standards W3C adopt LESS! Browser error/inspection doesn’t match original code Not a silver bullet to solve browser compatibility issues Developers still able to mess things up pretty bad CSS bloat Excessive CSS size if you’re not careful Potential browser performance issue Error reporting could be better

Integration with… Bootstrap Rails Tapestry ASP.NET Node.js PHP Django Play … Anything!

Extras: Mixin Libraries LESSHAT Lots of Love for LESS LESS Elements Bootstrap!

TOOLS AND USAGE

Usage: Integrated Best: native framework integration Compilation handled automatically JavaScript engines: V8, Rhino, NashornNashorn E.g. any Java/JVM based languageany Java/JVM based language Alternate implementations PHP, Python, Ruby (originally)… Edit LESS files directly, automatically converted to CSS Browser should get optimized, compressed CSS

Usage: Tools Edit LESS files, convert to CSS Use tools when no native integration is available Must recompile “manually” if LESS files are modified Keep generated CSS in version control – compression results in full-file changes – ick! Add to build pipeline? Limited support.. Typically run in the background and automatically update CSS when LESS files are changed Browser should get optimized, compressed CSS

Tools: Koala Cross-platform SASS LESS JS Coffeescript Minify LESS 1.5!

Tools: CodeKit MAC only SASS LESS JS Coffeescript

Tools: SimpLESS Cross- platform LESS only Issues with LESS > 1.3? Otherwise, great

Tools… Lots more… See the lesscss.org site for some of them Node.js command line: lessc

Usage: In-Browser Directly edit LESS files Browser downloads LESS files directly Compilation to CSS done via JavaScript Use <link rel=“stylesheet/less” Use inline Most risky Slowest Development mode!

Usage: In-Browser Easiest way to get started! (Don’t do this in red; body > h1 { } <script type="text/javascript" src=“ Hello, LESS

LANGUAGE DETAILS

Basic Structure Superset of CSS Valid CSS should be valid LESS Imperfect?

Comments CSS-style comments Included in output by default C-style single-line comments, too!!

Variables Define variables beginning My only value; syntax Can hold different types of units, LESS is smart about units: px, em, hex/RGB colors

Variable Interpolation Variables interpolated in strings Make sure you know your data type! Interpolated in selectors & rules Must use syntax

Variable Scope Variables scoped logically within braces Variables from mixins available in scope where used

Nesting LESS allows nested selectors Compiled logically to combine selectors in resulting handled appropriately

Nesting Ampersand used to concatenate to parent selector Will concatenate just about anything Easy to nest too deep – not necessary to mimic HTML

Nesting Ampersand also used to “reverse nesting order”.parent & will actually go at the beginning, not reversed order – better! Old browser support

Mixins Mixins will copy style information into context One of the most important features to avoid duplication

Mixins Mixins support parameters Default values Variables can be scoped within mixin definition

Mixins Parameterless mixins are hidden from output More complicated usage scenarios supported Nested mixins ‘unlocked’ with scoped variables…

Namespaces Enclose rules in namespaces Use hidden mixins to keep from output

Pattern matching Mixins matched based on for any value, will always be included Match on parameter count I’ve never had a need for this…

Guards Basic inclusion/exclusion rules for mixins Uses the when keyword after mixin declaration Also: when and > 0) {... }

Guards Supports: > >= = =< < And functions: iscolor isnumber isstring iskeyword isurl ispixel ispercentage isem Isunit I’ve never had a need for this, either… not a hipster!

both CSS and LESS files Omit.less extension, if desired, for LESS files CSS files not processed Imports make variables available in context

:extend Joins to existing style rules – a way out of CSS bloat by adding selectors to parent definition Introduced in LESS 1.4 Last remaining deficiency vs. SASS? !! Can’t have parameters like mixins

:extend Extend matches all outputs of specific params Extend multiple comma sparated

Operations LESS is smart about math Units remain intact, can mix some types Can use hex color values in operations

Functions Lots of built-in functions Color: lighten, darken, desaturate, … Math: ceil, floor, round, … See lesscss.org for more information

LEAN HTML

Why lean HTML? Performant web sites Lean HTML Mobile device friendly Smaller downloads Fewer DOM elements What about full-blown AJAX sites? Easier to generate with JS

Why lean HTML? Easier to restyle – content separated from styling Good for multiple developers Philosophical change: Include appropriate HTML Think in terms of components Aligns with recent development: Angular, React, etc.. Avoid including styling information LESS enables this by moving styling to CSS

CSS Anti-patterns Styling directly included in markup Solution? renaming CSS classes, do not change usage patterns

CSS Anti-patterns Regardless of the terminology, style information is directly included in the markup Why? It would require lots of duplicate CSS to do otherwise Grid systems - eek! Chock full o’ anti-patterns

Maintainability Avoid needless classes Avoid lots of unnecessary nesting Modern browsers make styling much easier Include lean HTML Never use IDs, at least not for styling No performance benefit

Target & Apply Target (use selectors) This is what CSS is built for You already know jQuery & CSS selectors, right? Apply style rules In your CSS, marry the targeted elements to the styling information This is what LESS makes easy to do!

LESS for styling Using mixins and :extend functionality, move the choice of styling to the rules, not the HTML Based on minimal HTML, easy to apply selectors

Rethink your HTML

Alternatives to LESS SASS SCSS similar to CSS syntax Compass is said to be awesome Old SASS syntax == bad! Uses $ for vars, smart! Stylus Syntax “different” than CSS Plain-old CSS CSS pre-processors are for hipsters!

Try it! Questions? Comments? Editor: kzantow.github.io/fiddle-lesskzantow.github.io/fiddle-less less2css.org Thanks!