SlideShare a Scribd company logo
Simplify your CSS
with Stylus and Nib
  Christian Joudrey - @cjoudrey
The current state of CSS

#comments li {
  background-color: #FEFEFE;
}

#comments .author {
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  border-radius: 5px;
}
Stylus




“Expressive, robust, feature-rich CSS language
built for nodejs”
Main differences
• Get rid of syntactic sugar (brackets, semi-colons, colons)

• Enforced indentation

• Don't repeat yourself (DRY)


body
  font 12px Helvetica, Arial, sans-serif

a.button
  -webkit-border-radius 5px
  -moz-border-radius 5px
  border-radius 5px
Variables
$font-size = 14px

body
  font $font-size Helvetica, Arial, sans-serif
Mixins

body
  font 12px Helvetica, Arial, sans-serif

border-radius()
  -webkit-border-radius arguments
  -moz-border-radius arguments
  border-radius arguments

a.button
  border-radius 5px
Nested selectors

#comments                   #comments h1 {
  h1                          font-size: 14px;
     font-size 14px         }
  a
     color black            #comments a {
                              color: black;
    &:hover                 }
      color blue
                            #comments a:hover {
                              color: blue;
                            }
Nib




“Stylus mixins, utilities, components, and
gradient image generation. CSS is your bitch!”
Vendor prefixes
@import 'nib'                #comments {
                               -webkit-border-radius: 4px;
                               -moz-border-radius: 4px;
#comments                      border-radius: 4px;
  border-radius 4px            -webkit-box-shadow: 0 0 1px #000;
                               -moz-box-shadow: 0 0 1px #000;
  box-shadow 0 0 1px black     box-shadow: 0 0 1px #000;
  p                          }
    opacity 0.75
                             #comments p {
                               opacity: 0.75;
                               filter: progid:DXIm[...]pha(Opacity=75);
                             }
Clearfix
@import 'nib'         .cf {
                        zoom: 1;
.cf                   }
  clearfix()          .cf:before,
                      .cf:after {
                        content: "";
                        display: table;
                      }
                      .cf:after {
                        clear: both;
                      }
Hide-text
@import 'nib'          #slogan {
                          text-indent: -99999em;
#slogan                   overflow: hidden;
  hide-text()             text-align: left;
                       }
and a lot more...
The best part is...
• It's all optional, you can mix and match Stylus and CSS

• Slowly integrate it in your existing CSS


                @import 'nib'

                #comments {
                  border-radius: 4px;
                  border: 1px solid black;
                }
Express Middleware
var express = require('express'),
    stylus = require('stylus'),
    nib = require('nib'),
    app = express.createServer();

// ...

app.use(stylus.middleware({
  src: __dirname + '/public',
  compile: function (str, path){
     return stylus(str)
       .set('filename', path)
       .set('compress', true)
       .use(nib());
  }
}));
Command-line Tool

$ npm install -g stylus


$ stylus main.styl
   compiled main.css


$ stylus -u nib main.styl
   compiled main.css
Interesting Links

• Stylus: http://learnboost.github.com/stylus

• Nib: https://github.com/visionmedia/nib

More Related Content

PPTX
CSS Walktrough Internship Course
PDF
DotNetNuke World CSS3
PDF
Writing your own DSL
PDF
Canvas - HTML 5
PDF
Crosswords Puzzles - QueensJS
PPTX
HTML 5_Canvas
PPTX
Html canvas
PPT
Dependency Injection in Scala - Beyond the Cake Pattern
CSS Walktrough Internship Course
DotNetNuke World CSS3
Writing your own DSL
Canvas - HTML 5
Crosswords Puzzles - QueensJS
HTML 5_Canvas
Html canvas
Dependency Injection in Scala - Beyond the Cake Pattern

Viewers also liked (20)

DOCX
New Product Development Report
PPTX
NETCONF YANG tutorial
PPT
37 Ways for New Product Ideas
DOCX
Report on launching of new product
PPTX
A 30-minute Introduction to NETCONF and YANG
PDF
Ballast Water Treatment with VOS™ | N.E.I. Treatment Systems
PPT
My Communication Lab
PPTX
KABLOSUZ PROB YARDIMIYLA GEOPHONE SİSTEMİ TASARIMI
PDF
Qu’est-ce que la carte MasterCard prépayée paysafecard?
PPT
Lotus Notes Migration
PPTX
Tc basics
PDF
Netezza vs teradata
PPT
Immunohistochemistry (IHC)Staining Steps
PDF
MicroStrategy Design Challenges - Tips and Best Practices
PPTX
OOW15 - Testing Oracle E-Business Suite Best Practices
PDF
Speech Lessons 1-7
DOCX
PROJECT REPORT ON CAMELS FRAMEWORK
PPTX
Processed Meat Packaging - Anas Shaikh - 13FET1006
DOCX
key word indexing and their types with example
PDF
31-P NMR SPECTROSCOPY
New Product Development Report
NETCONF YANG tutorial
37 Ways for New Product Ideas
Report on launching of new product
A 30-minute Introduction to NETCONF and YANG
Ballast Water Treatment with VOS™ | N.E.I. Treatment Systems
My Communication Lab
KABLOSUZ PROB YARDIMIYLA GEOPHONE SİSTEMİ TASARIMI
Qu’est-ce que la carte MasterCard prépayée paysafecard?
Lotus Notes Migration
Tc basics
Netezza vs teradata
Immunohistochemistry (IHC)Staining Steps
MicroStrategy Design Challenges - Tips and Best Practices
OOW15 - Testing Oracle E-Business Suite Best Practices
Speech Lessons 1-7
PROJECT REPORT ON CAMELS FRAMEWORK
Processed Meat Packaging - Anas Shaikh - 13FET1006
key word indexing and their types with example
31-P NMR SPECTROSCOPY
Ad

Similar to Simplify your CSS with Stylus and Nib (20)

KEY
Stylesheets of the future with Sass and Compass
PDF
Accelerated Stylesheets
PDF
Compass And Sass(Tim Riley)
KEY
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
PDF
CSS Extenders
PDF
Big Design Conference: CSS3
PPTX
Website trends 2012 presentation
PDF
Do more with {less}
PDF
How else does Adobe help in HTML5 development?
PDF
Exam 70 480 CSS3 at Jinal Desai .NET
PDF
Compass, Sass, and the Enlightened CSS Developer
KEY
Creating Art with Codes - CSS3
KEY
Using Sass - Building on CSS
PPTX
Less css
PPTX
Doing More With Less
KEY
CSS and CSS3
PPTX
Embrace the Mullet: CSS is the 'Party in the Back' (a CSS How-to)
PDF
Preprocessor presentation
PPTX
CSS: A Slippery Slope to the Backend
Stylesheets of the future with Sass and Compass
Accelerated Stylesheets
Compass And Sass(Tim Riley)
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
CSS Extenders
Big Design Conference: CSS3
Website trends 2012 presentation
Do more with {less}
How else does Adobe help in HTML5 development?
Exam 70 480 CSS3 at Jinal Desai .NET
Compass, Sass, and the Enlightened CSS Developer
Creating Art with Codes - CSS3
Using Sass - Building on CSS
Less css
Doing More With Less
CSS and CSS3
Embrace the Mullet: CSS is the 'Party in the Back' (a CSS How-to)
Preprocessor presentation
CSS: A Slippery Slope to the Backend
Ad

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
Teaching material agriculture food technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Cloud computing and distributed systems.
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Encapsulation theory and applications.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Modernizing your data center with Dell and AMD
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
A Presentation on Artificial Intelligence
Electronic commerce courselecture one. Pdf
Unlocking AI with Model Context Protocol (MCP)
Review of recent advances in non-invasive hemoglobin estimation
Reach Out and Touch Someone: Haptics and Empathic Computing
Teaching material agriculture food technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Machine learning based COVID-19 study performance prediction
Cloud computing and distributed systems.
Understanding_Digital_Forensics_Presentation.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Encapsulation theory and applications.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
MYSQL Presentation for SQL database connectivity
Per capita expenditure prediction using model stacking based on satellite ima...
Modernizing your data center with Dell and AMD
NewMind AI Monthly Chronicles - July 2025
Spectral efficient network and resource selection model in 5G networks
The Rise and Fall of 3GPP – Time for a Sabbatical?
A Presentation on Artificial Intelligence

Simplify your CSS with Stylus and Nib

  • 1. Simplify your CSS with Stylus and Nib Christian Joudrey - @cjoudrey
  • 2. The current state of CSS #comments li { background-color: #FEFEFE; } #comments .author { -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; }
  • 3. Stylus “Expressive, robust, feature-rich CSS language built for nodejs”
  • 4. Main differences • Get rid of syntactic sugar (brackets, semi-colons, colons) • Enforced indentation • Don't repeat yourself (DRY) body font 12px Helvetica, Arial, sans-serif a.button -webkit-border-radius 5px -moz-border-radius 5px border-radius 5px
  • 5. Variables $font-size = 14px body font $font-size Helvetica, Arial, sans-serif
  • 6. Mixins body font 12px Helvetica, Arial, sans-serif border-radius() -webkit-border-radius arguments -moz-border-radius arguments border-radius arguments a.button border-radius 5px
  • 7. Nested selectors #comments #comments h1 { h1 font-size: 14px; font-size 14px } a color black #comments a { color: black; &:hover } color blue #comments a:hover { color: blue; }
  • 8. Nib “Stylus mixins, utilities, components, and gradient image generation. CSS is your bitch!”
  • 9. Vendor prefixes @import 'nib' #comments { -webkit-border-radius: 4px; -moz-border-radius: 4px; #comments border-radius: 4px; border-radius 4px -webkit-box-shadow: 0 0 1px #000; -moz-box-shadow: 0 0 1px #000; box-shadow 0 0 1px black box-shadow: 0 0 1px #000; p } opacity 0.75 #comments p { opacity: 0.75; filter: progid:DXIm[...]pha(Opacity=75); }
  • 10. Clearfix @import 'nib' .cf { zoom: 1; .cf } clearfix() .cf:before, .cf:after { content: ""; display: table; } .cf:after { clear: both; }
  • 11. Hide-text @import 'nib' #slogan { text-indent: -99999em; #slogan overflow: hidden; hide-text() text-align: left; }
  • 12. and a lot more...
  • 13. The best part is... • It's all optional, you can mix and match Stylus and CSS • Slowly integrate it in your existing CSS @import 'nib' #comments { border-radius: 4px; border: 1px solid black; }
  • 14. Express Middleware var express = require('express'), stylus = require('stylus'), nib = require('nib'), app = express.createServer(); // ... app.use(stylus.middleware({ src: __dirname + '/public', compile: function (str, path){ return stylus(str) .set('filename', path) .set('compress', true) .use(nib()); } }));
  • 15. Command-line Tool $ npm install -g stylus $ stylus main.styl compiled main.css $ stylus -u nib main.styl compiled main.css
  • 16. Interesting Links • Stylus: http://learnboost.github.com/stylus • Nib: https://github.com/visionmedia/nib