SlideShare una empresa de Scribd logo
1 de 40
Descargar para leer sin conexión
DRUPAL & CSS
PREPROCESSORS
VS

CSS preprocessors like Sass and LESS are languages made up of
normal CSS plus some extra features, such as variables, nested
rules, math, mixins, etc.

Helper applications can convert stylesheets written in Sass or
LESS to standard CSS that can be included normally with your
theme.
       LESS                        Sass & Compass
       http://lesscss.org          http://sass-lang.com
                                   http://compass-style.org
Why use a
preprocessor?
Because CSS SUCKS
                             (sometimes)


  Redundancy
  #block-menu-block-main-menu-level-tertiary .content a:link {}
  #block-menu-block-main-menu-level-tertiary .content a:visited {}
  #block-menu-block-main-menu-level-tertiary .content a:hover,
  #block-menu-block-main-menu-level-tertiary .content a:focus {}

  Redundancy
  a { color: #cff; }
  .box { border-color: #cff; }

  Redundancy
  .box {
  	

    -webkit-box-shadow: 1px 1px 10px 3px #ccc;
  	

    -moz-box-shadow: 1px 1px 10px 3px #ccc;
  	

    box-shadow: 1px 1px 10px 3px #ccc;
  }




  From John Albins WIlkins’ “SASS: CSS with Attitude,” Drupal Design Camp Berlin 2011.
(From Matt Farina and Nathan Smith's "Using Sass & Compass in Drupal Theming" http://denver2012.drupal.org/program/sessions/using-sass-compass-drupal-theming)
Preprocessors make CSS
            more awesomer.
Unlike in standard CSS, with a preprocessor you can:
1. Build complicated mixins
2. Create variables and perform operations on variables like in PHP
   (Mixins and Parametric Mixins)
3. Nest rules and syntax
4. Accept math operations and computations inline
5. Change scope
6. Evaluate JS inline
7. Organize your CSS rules in hierarchies; group things logically
8. Create reusable code to use on any project
Examples of
LESS and SASS
VARIABLES

SASS                                                           LESS
$color: red;                                                   @color: red;
div {                                                          div {
  color: $color;                                                 color: @color;
}                                                              }




Chris Epstein: Sass/Less Comparison, https://gist.github.com/674726
NESTED SELECTORS

SASS                                                          LESS
p {                                                           p {
  a {                                                           a {
    color: red;                                                   color: red;
    &:hover {                                                     &:hover {
      color: blue;                                                  color: blue;
    }                                                             }
  }                                                             }
}                                                             }




Chris Epstein: Sass/Less Comparison, https://gist.github.com/674726
MIXINS

SASS                                                           LESS
@mixin bordered {                                              .bordered {
  border-top: dotted 1px black;                                   border-top: dotted 1px black;
  border-bottom: solid 2px black;                                 border-bottom: solid 2px black;
}                                                              }

#menu a {                                                      #menu a {
  @include bordered;                                              .bordered;
}                                                              }




Chris Epstein: Sass/Less Comparison, https://gist.github.com/674726
MIXINS WITH ARGUMENTS

SASS                                                        LESS
@mixin bordered($width: 2px) {                              .bordered(@width: 2px) {
  border: $width solid black;                                  border: @width solid black;
}                                                           }

#menu a {                                                   #menu a {
  @include bordered(4px);                                      .bordered(4px);
}                                                           }




Chris Epstein: Sass/Less Comparison, https://gist.github.com/674726
SELECTOR INHERITANCE

SASS                                                           LESS
.bordered {                                                    N/A
  border: 1px solid back;
}

#menu a {
  @extend .bordered;
}




Chris Epstein: Sass/Less Comparison, https://gist.github.com/674726
CONDITIONALS & CONTROLS

SASS                                               LESS
@if lightness($color) > 30% {                      .mixin (@color) when (lightness(@color) > 30%) {
  background-color: black;                           background-color: black;
}                                                  }
@else {                                            .mixin (@color) when (lightness(@color) =< 30%) {
  background-color: white;                           background-color: white;
}                                                  }

@for $i from 1px to 10px {
  .border-#{i} {
    border: $i solid blue;
  }
}




       Chris Epstein: Sass/Less Comparison, https://gist.github.com/674726
NAMESPACES
SASS                                              LESS
N/A                                               #bundle () {
                                                    .red { background-color: red }
                                                    .green { background-color: green }
                                                  }

                                                  .foo {
                                                    #bundle > .red;
                                                  }

                                                  COMPILES AS:

                                                  .foo {
                                                    background-color: red;
                                                  }

      Chris Epstein: Sass/Less Comparison, https://gist.github.com/674726
What does all this mean?
What does all this mean?

  Libraries!
What does all this mean?

  Libraries!
What does all this mean?

  Libraries!
What does all this mean?

  Libraries!
What does all this mean?

  Libraries!
STYLE LIBRARIES


Both LESS/SASS can be used to create personal libraries of
mixins and variables, which you can import into projects
with a single line: @import “import-mixins.less”;
PRE-BUILT LIBRARIES

Many pre-built collections are available for both LESS and Sass.
The best known are Bootstrap for LESS and Compass for Sass.
BOOTSTRAP
Bootstrap for LESS includes mixins and variables for:
Global styles                  Buttons
Grid systems                   Navigation
Layouts                        Navbars
@media queries                 Breadcrumbs
Typography                     Pagination
Tables                         Labels and badges
Forms                          Thumbnails
Images                         Alerts
Icons                          Progress bars
Dropdowns

It also includes 13 Javascript scripts for everything from dropdowns and buttons to popups and
carousels.
COMPASS
Compass is a helper library for Sass. It includes libraries of shared mixins, a package manager to add
additional extension libraries, and an executable that can easily convert Sass files into CSS.
Reset                                Helper functions for:                 CSS3 Mixins:
Grid Background                      Color Stops                           Appearance              Font Face
Sticky Footer                        Colors                                Background Clip         Hyphenation
Stretching                           Constants                             Background Origin       Images
Typography                           Cross Browser                         Background Size         Inline Block
Vertical Rhythm                      Display Helpers                       Border Radius           Opacity
Color                                Font Files                            Box                     Shared Utilities
General                              Image Dimensions                      Box Shadow              Text Shadow
Print                                Inline Data                           Box Sizing              Transform
Sprites                              Math                                  CSS Regions             Transition
Tables                               Selectors                             CSS3 Pie                User Interface
                                     Sprites                               Columns
                                     URLs                                  Filter

In addition, many 3rd-party extensions exist for Compass, including a Sass version of Bootstrap:
Sassy Buttons: fancy CSS3 button - jaredhardy.com/sassy-buttons
Modular Scale: calculate typographic scales - github.com/scottkellum/modular-scale
Survival Kit: toolset for designing web sites in the browser - thecodingdesigner.com/survivalkit
Susy: responsive grids for Compass - susy.oddbird.net
Singularity Grid: responsive grid system - singularity.gs
Breakpoint: really simple media queries - breakpoint-sass.com
Text shadow - sassymothereffingtextshadow.com
Libraries are nice for reusing code...
and sharing with your team.
How do LESS
and Sass work?
COMPILING CSS
LESS and SASS are preprocessed languages that must be
compiled before being served to the browser.
There are three ways to compile LESS & Sass:
• Server-side
• In Drupal
• Pre-compiled


                                     The exception is including
                                     less.js on the page and
                                     compiling client-side.
                                     Not recommended.
COMPILING SERVER-SIDE

LESS & Sass can be converted on-the-fly using PHP.

LessPHP (http://leafo.net/lessphp) compiles LESS at
runtime, using server-side PHP rather than client-side
Javascript. This method requires lessphp and the creation
of a styles.php.

SASS typically runs on Ruby and is processed server-side.
PHPSass (http://www.phpsass.com) is a PHP compiler for
SASS.

For both, compiling on-the-fly can make development
more difficult, and there may be some performance and
caching issues.
COMPILING IN DRUPAL
LESS CSS Preprocessor - http://drupal.org/project/less
The LESS module parses LESS on the server. Once LESS is compiled, it's cached by the Drupal’s default CSS
caching, so the performance hit is negligible. The modules will automatically process any LESS files that are
added using drupal_add_css or through your theme's .info file. Works with Drupal's CSS compression.
Requires the Libraries API and lessphp (http://leafo.net/lessphp/). Place LESS and Libraries in your modules
directory and lessphp in your libraries directory (sites/all/libraries/lessphp/lessc.inc.php).



Sassy - http://drupal.org/project/sassy
The Sassy module automatically compiles SASS/SCSS into CSS via PHP, rather than Ruby. Compiles all .scss
and .sass files that are added using drupal_add_css or through your theme's .info file. Includes support for
Compass, Bootstrap, and Foundation. Works with Drupal's CSS compression.
Requires the Prepro module, Libraries API, and PHPSass (http://github.com/richthegeek/phpsass/downloads).
Place Sassy, Prepro, and Libraries in your modules directory and PHPSass in your libraries directory.


NOTE: Sass (http://drupal.org/project/sass) is another module for Drupal that compiles SASS/SCSS files. However, PHP needs code
write access to theme.
COMPILING IN DRUPAL


The bad news.

Compiling broken LESS or
Sass can break your site.

Not good.
PRE-COMPILING
Many people recommend compiling LESS and Sass locally.
They suggest isolating LESS/Sass from Drupal by using a
compiler to watch your .less/.sass/.scss files, then compiling to
pure CSS files that you can deploy to your staging and
production servers.

Compiling locally makes sense. It takes advantage of first-party
releases of Sass and LESS directly. It avoids performance and
caching issues. And your site won’t break if you push broken
LESS or Sass.

If CSS preprocessors are really only useful during the
development phase, it makes sense to keep them there,
PRE-COMPILING: LESS
To compile LESS locally:

1. Add less.js to your development theme.

2. You can use a compiler like Less.app (http://incident57.com/less/) or
CodeKit (http://incident57.com/codekit/) to compile your LESS into CSS
before publishing on the web. But you could also compile LESS into CSS
using just your browser: view the source CSS in a browser and copy-n-paste
into a CSS file.
PRE-COMPILING: SASS/SCSS
You can use Compass.app or CodeKit to compile Sass locally, or you can
compile via the command-line:
1. If on Windows or Linux, set up Ruby - http://sonspring.com/journal/sass-for-designers.
2. Set up Compass & SASS: $gem install compass
3. Add config.rb to your theme directory (see next slide)
4. cd to your theme directory and run: $compass watch
   If you just want to flush cache and compile, run:
 $compass clean && compass compile

(From Matt Farina and Nathan Smith's "Using Sass & Compass in Drupal Theming" http://denver2012.drupal.org/program/sessions/
using-sass-compass-drupal-theming)
(From Matt Farina and Nathan Smith's "Using Sass & Compass in Drupal Theming" http://denver2012.drupal.org/program/sessions/using-sass-compass-drupal-theming)
DRUPAL CSS COMPRESSION




Even when you minimize compiled files, use Drupal’s CSS compression to benefit from:

1. Cache-busting. File name is changed to... “css_VvtjvgJd9tI4sfrm9jVFoHRnrEBsJlQs.css”

2. <link /> instead of <style>@import</style> (older IE versions are slower at the latter)

3. Full paths: Drupal replaces url(../images/file.png) with url(/full/path/to/images/file.png)
   — Useful if you have assets on a CDN or subdomain.

(From Matt Farina and Nathan Smith's "Using Sass & Compass in Drupal Theming" http://denver2012.drupal.org/program/sessions/using-sass-compass-drupal-theming)
Which is better--
 LESS or Sass?
THEIR SIMILARITIES
There really isn’t much difference between Sass and LESS.
1. They both have active communities.
2. Both will run on PHP.
3. LESS syntax was closer to CSS than Sass, but with the
   release of Sassy CSS (SCSS), this is no longer the case.
4. It’s just as easy, less fragile, and probably more secure to
   use Sass and LESS straight-up, rather than with a module.
   So there's no need to evaluate the Drupal modules.
5. Both should be used only for development and compiled
   locally, and both have decent compilers available.
THEIR DIFFERENCES
The main difference between LESS and Sass is in the
libraries and frameworks available for each.
           Sass                 LESS
           Compass              Bootstrap
           Foundation
           Bootstrap


In addition, more Drupal themes use Sass:
           Sass                 LESS
           Zen                  Basic
           AdaptiveTheme
           Basic
           Boilerplate
           Sasson
           Aurora
WHO’S USING WHAT?




Results from 13,000 respondents to Chris Coyier’s “Popularity of CSS Preprocessors” poll.



                  Why John Albin Wilkins choose SASS for Zen: "We picked Sass mostly
                  because it is a much more mature project, especially when you add
                  Compass into the mix. The answer to 'Does LESS have any supporting
                  libraries that can compare to Compass?' seems quite lacking."
CONCLUSION
                             (GRAND FINALE)




Use Sass for development only, compile locally
and share a team library.
LESS might be a little easier to learn and install. However:
★ In my research, I found more documentation and extensions for Sass.
★ I heard more people say they’d switched from LESS to Sass (never vice versa).
★ FireSass.
★ Sass has Compass, as well as the Sass version of Bootstrap.

Más contenido relacionado

La actualidad más candente

Elegant CSS Design In Drupal: LESS vs Sass
Elegant CSS Design In Drupal: LESS vs SassElegant CSS Design In Drupal: LESS vs Sass
Elegant CSS Design In Drupal: LESS vs SassMediacurrent
 
Introduction to SASS
Introduction to SASSIntroduction to SASS
Introduction to SASSJon Dean
 
CSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassCSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassLucien Lee
 
Sass: The Future of Stylesheets
Sass: The Future of StylesheetsSass: The Future of Stylesheets
Sass: The Future of Stylesheetschriseppstein
 
Syntactically awesome stylesheets (Sass)
Syntactically awesome stylesheets (Sass)Syntactically awesome stylesheets (Sass)
Syntactically awesome stylesheets (Sass)Tahmina Khatoon
 
Authoring Stylesheets with Compass & Sass
Authoring Stylesheets with Compass & SassAuthoring Stylesheets with Compass & Sass
Authoring Stylesheets with Compass & Sasschriseppstein
 
Advanced sass/compass
Advanced sass/compassAdvanced sass/compass
Advanced sass/compassNick Cooley
 
Preprocessor presentation
Preprocessor presentationPreprocessor presentation
Preprocessor presentationMario Noble
 
Sass and compass workshop
Sass and compass workshopSass and compass workshop
Sass and compass workshopShaho Toofani
 
Deep dive into sass
Deep dive into sassDeep dive into sass
Deep dive into sassKnoldus Inc.
 
Pacific Northwest Drupal Summit: Basic & SASS
Pacific Northwest Drupal Summit: Basic & SASSPacific Northwest Drupal Summit: Basic & SASS
Pacific Northwest Drupal Summit: Basic & SASSSteve Krueger
 
SASS is more than LESS
SASS is more than LESSSASS is more than LESS
SASS is more than LESSItai Koren
 
Wrangling the CSS Beast with Sass
Wrangling the CSS Beast  with SassWrangling the CSS Beast  with Sass
Wrangling the CSS Beast with SassRob Friesel
 
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and CompassBringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and CompassClaudina Sarahe
 
Doing More With Less
Doing More With LessDoing More With Less
Doing More With LessDavid Engel
 
Finding your way with Sass+Compass
Finding your way with Sass+CompassFinding your way with Sass+Compass
Finding your way with Sass+Compassdrywallbmb
 

La actualidad más candente (20)

Elegant CSS Design In Drupal: LESS vs Sass
Elegant CSS Design In Drupal: LESS vs SassElegant CSS Design In Drupal: LESS vs Sass
Elegant CSS Design In Drupal: LESS vs Sass
 
Introduction to SASS
Introduction to SASSIntroduction to SASS
Introduction to SASS
 
Css to-scss
Css to-scssCss to-scss
Css to-scss
 
CSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassCSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & Compass
 
Sass: The Future of Stylesheets
Sass: The Future of StylesheetsSass: The Future of Stylesheets
Sass: The Future of Stylesheets
 
LESS
LESSLESS
LESS
 
Syntactically awesome stylesheets (Sass)
Syntactically awesome stylesheets (Sass)Syntactically awesome stylesheets (Sass)
Syntactically awesome stylesheets (Sass)
 
Authoring Stylesheets with Compass & Sass
Authoring Stylesheets with Compass & SassAuthoring Stylesheets with Compass & Sass
Authoring Stylesheets with Compass & Sass
 
Advanced sass/compass
Advanced sass/compassAdvanced sass/compass
Advanced sass/compass
 
Preprocessor presentation
Preprocessor presentationPreprocessor presentation
Preprocessor presentation
 
Sass and compass workshop
Sass and compass workshopSass and compass workshop
Sass and compass workshop
 
Deep dive into sass
Deep dive into sassDeep dive into sass
Deep dive into sass
 
Pacific Northwest Drupal Summit: Basic & SASS
Pacific Northwest Drupal Summit: Basic & SASSPacific Northwest Drupal Summit: Basic & SASS
Pacific Northwest Drupal Summit: Basic & SASS
 
SASS is more than LESS
SASS is more than LESSSASS is more than LESS
SASS is more than LESS
 
Wrangling the CSS Beast with Sass
Wrangling the CSS Beast  with SassWrangling the CSS Beast  with Sass
Wrangling the CSS Beast with Sass
 
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and CompassBringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
 
SASS Preprocessor
SASS PreprocessorSASS Preprocessor
SASS Preprocessor
 
Doing More With Less
Doing More With LessDoing More With Less
Doing More With Less
 
Finding your way with Sass+Compass
Finding your way with Sass+CompassFinding your way with Sass+Compass
Finding your way with Sass+Compass
 
Sass
SassSass
Sass
 

Destacado

Estonian Web CMS Market Overview 2015
Estonian Web CMS Market Overview 2015Estonian Web CMS Market Overview 2015
Estonian Web CMS Market Overview 2015Wunderkraut Estonia
 
How to choose between Joomla, Drupal and Wordpress - Is there a best choice? ...
How to choose between Joomla, Drupal and Wordpress - Is there a best choice? ...How to choose between Joomla, Drupal and Wordpress - Is there a best choice? ...
How to choose between Joomla, Drupal and Wordpress - Is there a best choice? ...Marco Barbosa
 
Sass - Getting Started with Sass!
Sass - Getting Started with Sass!Sass - Getting Started with Sass!
Sass - Getting Started with Sass!Eric Sembrat
 
Introduction to WordPress
Introduction to WordPressIntroduction to WordPress
Introduction to WordPressEunus Hosen
 
High Profile Websites Powered by Drupal
High Profile Websites Powered by DrupalHigh Profile Websites Powered by Drupal
High Profile Websites Powered by DrupalAgnian
 
State of the Word 2011
State of the Word 2011State of the Word 2011
State of the Word 2011photomatt
 

Destacado (8)

Estonian Web CMS Market Overview 2015
Estonian Web CMS Market Overview 2015Estonian Web CMS Market Overview 2015
Estonian Web CMS Market Overview 2015
 
How to choose between Joomla, Drupal and Wordpress - Is there a best choice? ...
How to choose between Joomla, Drupal and Wordpress - Is there a best choice? ...How to choose between Joomla, Drupal and Wordpress - Is there a best choice? ...
How to choose between Joomla, Drupal and Wordpress - Is there a best choice? ...
 
WordPress vs Joomla vs Drupal
WordPress vs Joomla vs DrupalWordPress vs Joomla vs Drupal
WordPress vs Joomla vs Drupal
 
Sass presentation
Sass presentationSass presentation
Sass presentation
 
Sass - Getting Started with Sass!
Sass - Getting Started with Sass!Sass - Getting Started with Sass!
Sass - Getting Started with Sass!
 
Introduction to WordPress
Introduction to WordPressIntroduction to WordPress
Introduction to WordPress
 
High Profile Websites Powered by Drupal
High Profile Websites Powered by DrupalHigh Profile Websites Powered by Drupal
High Profile Websites Powered by Drupal
 
State of the Word 2011
State of the Word 2011State of the Word 2011
State of the Word 2011
 

Similar a Drupal & CSS Preprocessors

Sass and Compass - Getting Started
Sass and Compass - Getting StartedSass and Compass - Getting Started
Sass and Compass - Getting Startededgincvg
 
Simple introduction Sass
Simple introduction SassSimple introduction Sass
Simple introduction SassZeeshan Ahmed
 
Learn Sass and Compass quick
Learn Sass and Compass quickLearn Sass and Compass quick
Learn Sass and Compass quickBilly Shih
 
Save time by using SASS/SCSS
Save time by using SASS/SCSSSave time by using SASS/SCSS
Save time by using SASS/SCSSBerit Hlubek
 
Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)emrox
 
Getting Started with Sass & Compass
Getting Started with Sass & CompassGetting Started with Sass & Compass
Getting Started with Sass & CompassRob Davarnia
 
CSS3 is Not Magic Pixie Dust
CSS3 is Not Magic Pixie DustCSS3 is Not Magic Pixie Dust
CSS3 is Not Magic Pixie DustKyle Adams
 
Dallas Drupal Days 2012 - Introduction to less sass-compass
Dallas Drupal Days 2012  - Introduction to less sass-compassDallas Drupal Days 2012  - Introduction to less sass-compass
Dallas Drupal Days 2012 - Introduction to less sass-compassChris Lee
 
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsMobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsKaelig Deloumeau-Prigent
 
CSS with LESS for #jd13nl
CSS with LESS for #jd13nlCSS with LESS for #jd13nl
CSS with LESS for #jd13nlHans Kuijpers
 
Sass - Making CSS fun again.
Sass - Making CSS fun again.Sass - Making CSS fun again.
Sass - Making CSS fun again.Gabriel Neutzling
 

Similar a Drupal & CSS Preprocessors (20)

CSS Extenders
CSS ExtendersCSS Extenders
CSS Extenders
 
Sass and Compass - Getting Started
Sass and Compass - Getting StartedSass and Compass - Getting Started
Sass and Compass - Getting Started
 
Less & Sass
Less & SassLess & Sass
Less & Sass
 
Simple introduction Sass
Simple introduction SassSimple introduction Sass
Simple introduction Sass
 
Intro to SASS CSS
Intro to SASS CSSIntro to SASS CSS
Intro to SASS CSS
 
Theming and Sass
Theming and SassTheming and Sass
Theming and Sass
 
Learn Sass and Compass quick
Learn Sass and Compass quickLearn Sass and Compass quick
Learn Sass and Compass quick
 
Save time by using SASS/SCSS
Save time by using SASS/SCSSSave time by using SASS/SCSS
Save time by using SASS/SCSS
 
LESS CSS
LESS CSSLESS CSS
LESS CSS
 
Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)
 
Getting Started with Sass & Compass
Getting Started with Sass & CompassGetting Started with Sass & Compass
Getting Started with Sass & Compass
 
Advanced sass
Advanced sassAdvanced sass
Advanced sass
 
Why less?
Why less?Why less?
Why less?
 
Accelerated Stylesheets
Accelerated StylesheetsAccelerated Stylesheets
Accelerated Stylesheets
 
CSS3 is Not Magic Pixie Dust
CSS3 is Not Magic Pixie DustCSS3 is Not Magic Pixie Dust
CSS3 is Not Magic Pixie Dust
 
Dallas Drupal Days 2012 - Introduction to less sass-compass
Dallas Drupal Days 2012  - Introduction to less sass-compassDallas Drupal Days 2012  - Introduction to less sass-compass
Dallas Drupal Days 2012 - Introduction to less sass-compass
 
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsMobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
 
CSS with LESS for #jd13nl
CSS with LESS for #jd13nlCSS with LESS for #jd13nl
CSS with LESS for #jd13nl
 
SASS Lecture
SASS Lecture SASS Lecture
SASS Lecture
 
Sass - Making CSS fun again.
Sass - Making CSS fun again.Sass - Making CSS fun again.
Sass - Making CSS fun again.
 

Último

Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Nikki Chapple
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...itnewsafrica
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 

Último (20)

Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 

Drupal & CSS Preprocessors

  • 2. VS CSS preprocessors like Sass and LESS are languages made up of normal CSS plus some extra features, such as variables, nested rules, math, mixins, etc. Helper applications can convert stylesheets written in Sass or LESS to standard CSS that can be included normally with your theme. LESS Sass & Compass http://lesscss.org http://sass-lang.com http://compass-style.org
  • 4. Because CSS SUCKS (sometimes) Redundancy #block-menu-block-main-menu-level-tertiary .content a:link {} #block-menu-block-main-menu-level-tertiary .content a:visited {} #block-menu-block-main-menu-level-tertiary .content a:hover, #block-menu-block-main-menu-level-tertiary .content a:focus {} Redundancy a { color: #cff; } .box { border-color: #cff; } Redundancy .box { -webkit-box-shadow: 1px 1px 10px 3px #ccc; -moz-box-shadow: 1px 1px 10px 3px #ccc; box-shadow: 1px 1px 10px 3px #ccc; } From John Albins WIlkins’ “SASS: CSS with Attitude,” Drupal Design Camp Berlin 2011.
  • 5. (From Matt Farina and Nathan Smith's "Using Sass & Compass in Drupal Theming" http://denver2012.drupal.org/program/sessions/using-sass-compass-drupal-theming)
  • 6. Preprocessors make CSS more awesomer. Unlike in standard CSS, with a preprocessor you can: 1. Build complicated mixins 2. Create variables and perform operations on variables like in PHP (Mixins and Parametric Mixins) 3. Nest rules and syntax 4. Accept math operations and computations inline 5. Change scope 6. Evaluate JS inline 7. Organize your CSS rules in hierarchies; group things logically 8. Create reusable code to use on any project
  • 8. VARIABLES SASS LESS $color: red; @color: red; div { div { color: $color; color: @color; } } Chris Epstein: Sass/Less Comparison, https://gist.github.com/674726
  • 9. NESTED SELECTORS SASS LESS p { p { a { a { color: red; color: red; &:hover { &:hover { color: blue; color: blue; } } } } } } Chris Epstein: Sass/Less Comparison, https://gist.github.com/674726
  • 10. MIXINS SASS LESS @mixin bordered { .bordered { border-top: dotted 1px black; border-top: dotted 1px black; border-bottom: solid 2px black; border-bottom: solid 2px black; } } #menu a { #menu a { @include bordered; .bordered; } } Chris Epstein: Sass/Less Comparison, https://gist.github.com/674726
  • 11. MIXINS WITH ARGUMENTS SASS LESS @mixin bordered($width: 2px) { .bordered(@width: 2px) { border: $width solid black; border: @width solid black; } } #menu a { #menu a { @include bordered(4px); .bordered(4px); } } Chris Epstein: Sass/Less Comparison, https://gist.github.com/674726
  • 12. SELECTOR INHERITANCE SASS LESS .bordered { N/A border: 1px solid back; } #menu a { @extend .bordered; } Chris Epstein: Sass/Less Comparison, https://gist.github.com/674726
  • 13. CONDITIONALS & CONTROLS SASS LESS @if lightness($color) > 30% { .mixin (@color) when (lightness(@color) > 30%) { background-color: black; background-color: black; } } @else { .mixin (@color) when (lightness(@color) =< 30%) { background-color: white; background-color: white; } } @for $i from 1px to 10px { .border-#{i} { border: $i solid blue; } } Chris Epstein: Sass/Less Comparison, https://gist.github.com/674726
  • 14. NAMESPACES SASS LESS N/A #bundle () { .red { background-color: red } .green { background-color: green } } .foo { #bundle > .red; } COMPILES AS: .foo { background-color: red; } Chris Epstein: Sass/Less Comparison, https://gist.github.com/674726
  • 15. What does all this mean?
  • 16. What does all this mean? Libraries!
  • 17. What does all this mean? Libraries!
  • 18. What does all this mean? Libraries!
  • 19. What does all this mean? Libraries!
  • 20. What does all this mean? Libraries!
  • 21. STYLE LIBRARIES Both LESS/SASS can be used to create personal libraries of mixins and variables, which you can import into projects with a single line: @import “import-mixins.less”;
  • 22. PRE-BUILT LIBRARIES Many pre-built collections are available for both LESS and Sass. The best known are Bootstrap for LESS and Compass for Sass.
  • 23. BOOTSTRAP Bootstrap for LESS includes mixins and variables for: Global styles Buttons Grid systems Navigation Layouts Navbars @media queries Breadcrumbs Typography Pagination Tables Labels and badges Forms Thumbnails Images Alerts Icons Progress bars Dropdowns It also includes 13 Javascript scripts for everything from dropdowns and buttons to popups and carousels.
  • 24. COMPASS Compass is a helper library for Sass. It includes libraries of shared mixins, a package manager to add additional extension libraries, and an executable that can easily convert Sass files into CSS. Reset Helper functions for: CSS3 Mixins: Grid Background Color Stops Appearance Font Face Sticky Footer Colors Background Clip Hyphenation Stretching Constants Background Origin Images Typography Cross Browser Background Size Inline Block Vertical Rhythm Display Helpers Border Radius Opacity Color Font Files Box Shared Utilities General Image Dimensions Box Shadow Text Shadow Print Inline Data Box Sizing Transform Sprites Math CSS Regions Transition Tables Selectors CSS3 Pie User Interface Sprites Columns URLs Filter In addition, many 3rd-party extensions exist for Compass, including a Sass version of Bootstrap: Sassy Buttons: fancy CSS3 button - jaredhardy.com/sassy-buttons Modular Scale: calculate typographic scales - github.com/scottkellum/modular-scale Survival Kit: toolset for designing web sites in the browser - thecodingdesigner.com/survivalkit Susy: responsive grids for Compass - susy.oddbird.net Singularity Grid: responsive grid system - singularity.gs Breakpoint: really simple media queries - breakpoint-sass.com Text shadow - sassymothereffingtextshadow.com
  • 25. Libraries are nice for reusing code... and sharing with your team.
  • 26. How do LESS and Sass work?
  • 27. COMPILING CSS LESS and SASS are preprocessed languages that must be compiled before being served to the browser. There are three ways to compile LESS & Sass: • Server-side • In Drupal • Pre-compiled The exception is including less.js on the page and compiling client-side. Not recommended.
  • 28. COMPILING SERVER-SIDE LESS & Sass can be converted on-the-fly using PHP. LessPHP (http://leafo.net/lessphp) compiles LESS at runtime, using server-side PHP rather than client-side Javascript. This method requires lessphp and the creation of a styles.php. SASS typically runs on Ruby and is processed server-side. PHPSass (http://www.phpsass.com) is a PHP compiler for SASS. For both, compiling on-the-fly can make development more difficult, and there may be some performance and caching issues.
  • 29. COMPILING IN DRUPAL LESS CSS Preprocessor - http://drupal.org/project/less The LESS module parses LESS on the server. Once LESS is compiled, it's cached by the Drupal’s default CSS caching, so the performance hit is negligible. The modules will automatically process any LESS files that are added using drupal_add_css or through your theme's .info file. Works with Drupal's CSS compression. Requires the Libraries API and lessphp (http://leafo.net/lessphp/). Place LESS and Libraries in your modules directory and lessphp in your libraries directory (sites/all/libraries/lessphp/lessc.inc.php). Sassy - http://drupal.org/project/sassy The Sassy module automatically compiles SASS/SCSS into CSS via PHP, rather than Ruby. Compiles all .scss and .sass files that are added using drupal_add_css or through your theme's .info file. Includes support for Compass, Bootstrap, and Foundation. Works with Drupal's CSS compression. Requires the Prepro module, Libraries API, and PHPSass (http://github.com/richthegeek/phpsass/downloads). Place Sassy, Prepro, and Libraries in your modules directory and PHPSass in your libraries directory. NOTE: Sass (http://drupal.org/project/sass) is another module for Drupal that compiles SASS/SCSS files. However, PHP needs code write access to theme.
  • 30. COMPILING IN DRUPAL The bad news. Compiling broken LESS or Sass can break your site. Not good.
  • 31. PRE-COMPILING Many people recommend compiling LESS and Sass locally. They suggest isolating LESS/Sass from Drupal by using a compiler to watch your .less/.sass/.scss files, then compiling to pure CSS files that you can deploy to your staging and production servers. Compiling locally makes sense. It takes advantage of first-party releases of Sass and LESS directly. It avoids performance and caching issues. And your site won’t break if you push broken LESS or Sass. If CSS preprocessors are really only useful during the development phase, it makes sense to keep them there,
  • 32. PRE-COMPILING: LESS To compile LESS locally: 1. Add less.js to your development theme. 2. You can use a compiler like Less.app (http://incident57.com/less/) or CodeKit (http://incident57.com/codekit/) to compile your LESS into CSS before publishing on the web. But you could also compile LESS into CSS using just your browser: view the source CSS in a browser and copy-n-paste into a CSS file.
  • 33. PRE-COMPILING: SASS/SCSS You can use Compass.app or CodeKit to compile Sass locally, or you can compile via the command-line: 1. If on Windows or Linux, set up Ruby - http://sonspring.com/journal/sass-for-designers. 2. Set up Compass & SASS: $gem install compass 3. Add config.rb to your theme directory (see next slide) 4. cd to your theme directory and run: $compass watch If you just want to flush cache and compile, run: $compass clean && compass compile (From Matt Farina and Nathan Smith's "Using Sass & Compass in Drupal Theming" http://denver2012.drupal.org/program/sessions/ using-sass-compass-drupal-theming)
  • 34. (From Matt Farina and Nathan Smith's "Using Sass & Compass in Drupal Theming" http://denver2012.drupal.org/program/sessions/using-sass-compass-drupal-theming)
  • 35. DRUPAL CSS COMPRESSION Even when you minimize compiled files, use Drupal’s CSS compression to benefit from: 1. Cache-busting. File name is changed to... “css_VvtjvgJd9tI4sfrm9jVFoHRnrEBsJlQs.css” 2. <link /> instead of <style>@import</style> (older IE versions are slower at the latter) 3. Full paths: Drupal replaces url(../images/file.png) with url(/full/path/to/images/file.png) — Useful if you have assets on a CDN or subdomain. (From Matt Farina and Nathan Smith's "Using Sass & Compass in Drupal Theming" http://denver2012.drupal.org/program/sessions/using-sass-compass-drupal-theming)
  • 36. Which is better-- LESS or Sass?
  • 37. THEIR SIMILARITIES There really isn’t much difference between Sass and LESS. 1. They both have active communities. 2. Both will run on PHP. 3. LESS syntax was closer to CSS than Sass, but with the release of Sassy CSS (SCSS), this is no longer the case. 4. It’s just as easy, less fragile, and probably more secure to use Sass and LESS straight-up, rather than with a module. So there's no need to evaluate the Drupal modules. 5. Both should be used only for development and compiled locally, and both have decent compilers available.
  • 38. THEIR DIFFERENCES The main difference between LESS and Sass is in the libraries and frameworks available for each. Sass LESS Compass Bootstrap Foundation Bootstrap In addition, more Drupal themes use Sass: Sass LESS Zen Basic AdaptiveTheme Basic Boilerplate Sasson Aurora
  • 39. WHO’S USING WHAT? Results from 13,000 respondents to Chris Coyier’s “Popularity of CSS Preprocessors” poll. Why John Albin Wilkins choose SASS for Zen: "We picked Sass mostly because it is a much more mature project, especially when you add Compass into the mix. The answer to 'Does LESS have any supporting libraries that can compare to Compass?' seems quite lacking."
  • 40. CONCLUSION (GRAND FINALE) Use Sass for development only, compile locally and share a team library. LESS might be a little easier to learn and install. However: ★ In my research, I found more documentation and extensions for Sass. ★ I heard more people say they’d switched from LESS to Sass (never vice versa). ★ FireSass. ★ Sass has Compass, as well as the Sass version of Bootstrap.

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n