Copyright © 2014 APEX Consulting
APEX Developers -
Do More With Less !!
Roel Hartman
2
LESS
Leaner CSS
SASS
Syntactically Awesome StyleSheets
SCSS
Sassy CSS
OOCSS
Object Oriented CSS
You need a CSS Expert
Issue 1
Your CSS File(s) grows
Issue 2
No CSS code re-use
Issue 3
CSS is fragile
Issue 4
CSS increases 1:1 with HTML
Result
16
Your Solution …
Separating Structure from Skin
#button {
width: 200px;
height: 50px;
padding: 10px;
border: solid 1px #ccc;
background: linear-gradient(#ccc, #222);
box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}
#box {
width: 400px;
overflow: hidden;
border: solid 1px #ccc;
background: linear-gradient(#ccc, #222);
box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}
#widget {
width: 500px;
min-height: 200px;
overflow: auto;
border: solid 1px #ccc;
background: linear-gradient(#ccc, #222);
box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}
<html>
<div id=“box”>
<button id=“button” />
</div>
<div id=“widget”></div>
</html>
#button {
width: 200px;
height: 50px;
padding: 10px;
border: solid 1px #ccc;
background: linear-gradient(#ccc, #222);
box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}
#box {
width: 400px;
overflow: hidden;
border: solid 1px #ccc;
background: linear-gradient(#ccc, #222);
box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}
#widget {
width: 500px;
min-height: 200px;
overflow: auto;
border: solid 1px #ccc;
background: linear-gradient(#ccc, #222);
box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}
#button {
width: 200px;
height: 50px;
padding: 10px;
border: solid 1px #ccc;
background: linear-gradient(#ccc, #222);
box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}
#box {
width: 400px;
overflow: hidden;
border: solid 1px #ccc;
background: linear-gradient(#ccc, #222);
box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}
#widget {
width: 500px;
min-height: 200px;
overflow: auto;
border: solid 1px #ccc;
background: linear-gradient(#ccc, #222);
box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}
.button {
width: 200px;
height: 50px;
}
.box {
width: 400px;
overflow: hidden;
}
.widget {
width: 500px;
min-height: 200px;
overflow: auto;
}
.skin {
border: solid 1px #ccc;
background: linear-gradient(#ccc, #222);
box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}
.button {
width: 200px;
height: 50px;
}
.box {
width: 400px;
overflow: hidden;
}
.widget {
width: 500px;
min-height: 200px;
overflow: auto;
}
.skin {
border: solid 1px #ccc;
background: linear-gradient(#ccc, #222);
box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px;
}
<html>
<div class=“box skin”>
<button id=“button skin” />
</div>
<div id=“widget skin”></div>
</html>
Separating Structure from Skin
Separating Container from Content
div{
width: 200px;
height: 50px;
padding: 10px;
border: solid 1px #ccc;
}
div h3{
margin: 0px;
overflow: hidden;
border: solid 1px #ccc;
}
div p{
margin: 3px;
min-height: 200px;
overflow: auto;
border: solid 1px #ccc;
}
<html>
<div>
<h3>Header</h3>
</div>
<div>
<p>Paragraph</p>
</div>
</html>
.bordered{
border: solid 1px #ccc;
}
.container{
width: 200px;
height: 50px;
padding: 10px;
}
.region-header{
margin: 0px;
overflow: hidden;
}
.flexbox{
margin: 3px;
min-height: 200px;
overflow: auto;
}
<html>
<div class=“bordered container”>
<h3 class=“bordered region-header”>
Header
</h3>
</div>
<div class=“bordered container”>
<p class=“bordered flexbox”>Paragraph</p>
</div>
</html>
Separating Container from Content
LESS does MORE
preprocessor
.less file(s)
.css file
client server
<link rel="stylesheet" type="text/css" href="/css/demo2.css">
<aside class="sidemenu">
<h2 class="menu-header">Side menu</h2>
<ul class="menu-list">
<li class=“menu-list-item">
<a class="" href="page1.html">item 1</a>
</li>
<li class=“menu-list-item">
<a class="" href="page2.html">item 1</a>
</li>
</ul>
</aside>
<link rel="stylesheet" type="text/css" href="/css/demo2.css">
<aside id="sidemenu">
<h2>Side menu</h2>
<ul>
<li>
<a href="page1.html">item 1</a>
</li>
<li>
<a href="page2.html">item 1</a>
</li>
</ul>
</aside>
#sidemenu h2{
color: black;
font-size: 16px;
}
#sidemenu ul li a{
text-decoration: none;
color: green;
}
.sidemenu .menu-header{
color: black;
font-size: 16px;
}
.sidemenu .menu-link{
text-decoration: none;
color: green;
}
.sidemenu .menu-header{
color: black;
font-size: 16px;
}
.sidemenu .menu-link{
text-decoration: none;
color: green;
}
.sidemenu{
.menu-header{
color: black;
font-size: 16px;
}
.menu-link{
text-decoration: none;
color: green;
}
}
Nesting
.sidemenu{
.menu-header{
color: black;
font-size: 16px;
}
.menu-link{
text-decoration: none;
color: green;
}
}
@menu-header-color : black;
@menu-link-color : green;
@menu-font-size : 16px;
.sidemenu{
.menu-header{
color: @menu-header-color;
font-size: @menu-font-size;
}
.menu-link{
text-decoration: none;
color: @menu-link-color;
}
}
.sidemenu .menu-header {
color: #000000;
font-size: 16px;
}
.sidemenu .menu-link {
text-decoration: none;
color: #008000;
}
Variables
Calculations
@menu-header-color : black;
@menu-link-color : green;
@menu-font-size : 16px;
@delta-font-size : @menu-font-size / 4;
.sidemenu{
.menu-header{
color: @menu-header-color;
font-size: @menu-font-size;
}
.menu-link{
text-decoration: none;
color: @menu-link-color;
font-size: @menu-font-size - @delta-font-size;
}
}
@menu-header-color : black;
@menu-link-color : green;
@menu-font-size : 16px;
.sidemenu{
.menu-header{
color: @menu-header-color;
font-size: @menu-font-size;
}
.menu-link{
text-decoration: none;
color: @menu-link-color;
}
}
@menu-header-color : black;
@menu-link-color : green;
@menu-font-size : 16px;
.sidemenu{
.menu-header{
color: @menu-header-color;
font-size: @menu-font-size;
}
.menu-link{
text-decoration: none;
color: @menu-link-color;
font-size: 12px;
}
}
.sidemenu .menu-header {
color: #000000;
font-size: 16px;
}
.sidemenu .menu-link {
text-decoration: none;
color: #008000;
font-size: 12px;
}
Built-ins
@menu-header-color : black;
@menu-link-color : green;
@menu-font-size : 16px;
@delta-font-size : @menu-font-size / 4;
.sidemenu{
.menu-header{
color: @menu-header-color;
font-size: @menu-font-size;
}
.menu-link{
text-decoration: none;
color: @menu-link-color;
font-size: @menu-font-size - @delta-font-size;
}
}
.sidemenu {
background-color: #404040;
}
.sidemenu .menu-header {
color: #008000;
font-size: 16px;
}
.sidemenu .menu-link {
text-decoration: none;
color: #00e600;
font-size: 12px;
}
.sidemenu ul {
color: #00e600;
}
@menu-header-color : green;
@menu-link-color : lighten(@menu-header-color, 20%);
@menu-font-size : 16px;
@delta-font-size : @menu-font-size / 4;
.sidemenu{
background-color : greyscale(@menu-header-color,@menu-link-color);
.menu-header{
color: @menu-header-color;
font-size: @menu-font-size;
}
.menu-link{
text-decoration: none;
color: @menu-link-color;
font-size: @menu-font-size - @delta-font-size;
}
ul{
color: @menu-link-color;
}
}
Mixins
.roundedcorners{
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
.roundedcorners( @rad : 10px ){
-webkit-border-radius: @rad;
-moz-border-radius: @rad;
border-radius: @rad;
}
@menu-header-color : green;
@menu-link-color : lighten(@menu-header-color, 20%);
@menu-font-size : 16px;
@delta-font-size : @menu-font-size / 4;
.roundedcorners( @rad : 10px ){
-webkit-border-radius: @rad;
-moz-border-radius: @rad;
border-radius: @rad;
}
.sidemenu{
background-color : greyscale(@menu-header-color,@menu-link-color);
.roundedcorners( 25px );
.menu-header{
color: @menu-header-color;
font-size: @menu-font-size;
}
.menu-link{
text-decoration: none;
color: @menu-link-color;
font-size: @menu-font-size - @delta-font-size;
}
ul{
color: @menu-link-color;
}
}
.sidemenu{
background-color : greyscale(@menu-header-color,@menu-link-color);
.roundedcorners( 25px );
.menu-header{
color: @menu-header-color;
font-size: @menu-font-size;
}
.menu-link{
text-decoration: none;
color: @menu-link-color;
font-size: @menu-font-size - @delta-font-size;
}
ul{
color: @menu-link-color;
}
}
Use Building Blocks
Use Building Blocks
Other People’s
http://cl.ly/image/2S0k1q3Q2y2L
Copyright © 2014 APEX Consulting
Q& Aroel@apexconsulting.nl
http://www.apexconsulting.nl
36
roel@apexconsulting.nl
http://www.apexconsulting.nl
Copyright © 2014 APEX Consulting
37

APEX Developers : Do More With LESS !

  • 1.
    Copyright © 2014APEX Consulting APEX Developers - Do More With Less !! Roel Hartman
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
    You need aCSS Expert Issue 1
  • 12.
    Your CSS File(s)grows Issue 2
  • 13.
    No CSS codere-use Issue 3
  • 14.
  • 15.
    CSS increases 1:1with HTML Result
  • 16.
  • 17.
  • 18.
    #button { width: 200px; height:50px; padding: 10px; border: solid 1px #ccc; background: linear-gradient(#ccc, #222); box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px; } #box { width: 400px; overflow: hidden; border: solid 1px #ccc; background: linear-gradient(#ccc, #222); box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px; } #widget { width: 500px; min-height: 200px; overflow: auto; border: solid 1px #ccc; background: linear-gradient(#ccc, #222); box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px; } <html> <div id=“box”> <button id=“button” /> </div> <div id=“widget”></div> </html> #button { width: 200px; height: 50px; padding: 10px; border: solid 1px #ccc; background: linear-gradient(#ccc, #222); box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px; } #box { width: 400px; overflow: hidden; border: solid 1px #ccc; background: linear-gradient(#ccc, #222); box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px; } #widget { width: 500px; min-height: 200px; overflow: auto; border: solid 1px #ccc; background: linear-gradient(#ccc, #222); box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px; }
  • 19.
    #button { width: 200px; height:50px; padding: 10px; border: solid 1px #ccc; background: linear-gradient(#ccc, #222); box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px; } #box { width: 400px; overflow: hidden; border: solid 1px #ccc; background: linear-gradient(#ccc, #222); box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px; } #widget { width: 500px; min-height: 200px; overflow: auto; border: solid 1px #ccc; background: linear-gradient(#ccc, #222); box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px; } .button { width: 200px; height: 50px; } .box { width: 400px; overflow: hidden; } .widget { width: 500px; min-height: 200px; overflow: auto; } .skin { border: solid 1px #ccc; background: linear-gradient(#ccc, #222); box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px; }
  • 20.
    .button { width: 200px; height:50px; } .box { width: 400px; overflow: hidden; } .widget { width: 500px; min-height: 200px; overflow: auto; } .skin { border: solid 1px #ccc; background: linear-gradient(#ccc, #222); box-shadow: rgba(0, 0, 0, .5) 2px 2px 5px; } <html> <div class=“box skin”> <button id=“button skin” /> </div> <div id=“widget skin”></div> </html>
  • 21.
  • 22.
  • 23.
    div{ width: 200px; height: 50px; padding:10px; border: solid 1px #ccc; } div h3{ margin: 0px; overflow: hidden; border: solid 1px #ccc; } div p{ margin: 3px; min-height: 200px; overflow: auto; border: solid 1px #ccc; } <html> <div> <h3>Header</h3> </div> <div> <p>Paragraph</p> </div> </html>
  • 24.
    .bordered{ border: solid 1px#ccc; } .container{ width: 200px; height: 50px; padding: 10px; } .region-header{ margin: 0px; overflow: hidden; } .flexbox{ margin: 3px; min-height: 200px; overflow: auto; } <html> <div class=“bordered container”> <h3 class=“bordered region-header”> Header </h3> </div> <div class=“bordered container”> <p class=“bordered flexbox”>Paragraph</p> </div> </html>
  • 25.
  • 26.
  • 27.
  • 28.
    <link rel="stylesheet" type="text/css"href="/css/demo2.css"> <aside class="sidemenu"> <h2 class="menu-header">Side menu</h2> <ul class="menu-list"> <li class=“menu-list-item"> <a class="" href="page1.html">item 1</a> </li> <li class=“menu-list-item"> <a class="" href="page2.html">item 1</a> </li> </ul> </aside> <link rel="stylesheet" type="text/css" href="/css/demo2.css"> <aside id="sidemenu"> <h2>Side menu</h2> <ul> <li> <a href="page1.html">item 1</a> </li> <li> <a href="page2.html">item 1</a> </li> </ul> </aside> #sidemenu h2{ color: black; font-size: 16px; } #sidemenu ul li a{ text-decoration: none; color: green; } .sidemenu .menu-header{ color: black; font-size: 16px; } .sidemenu .menu-link{ text-decoration: none; color: green; }
  • 29.
    .sidemenu .menu-header{ color: black; font-size:16px; } .sidemenu .menu-link{ text-decoration: none; color: green; } .sidemenu{ .menu-header{ color: black; font-size: 16px; } .menu-link{ text-decoration: none; color: green; } } Nesting
  • 30.
    .sidemenu{ .menu-header{ color: black; font-size: 16px; } .menu-link{ text-decoration:none; color: green; } } @menu-header-color : black; @menu-link-color : green; @menu-font-size : 16px; .sidemenu{ .menu-header{ color: @menu-header-color; font-size: @menu-font-size; } .menu-link{ text-decoration: none; color: @menu-link-color; } } .sidemenu .menu-header { color: #000000; font-size: 16px; } .sidemenu .menu-link { text-decoration: none; color: #008000; } Variables
  • 31.
    Calculations @menu-header-color : black; @menu-link-color: green; @menu-font-size : 16px; @delta-font-size : @menu-font-size / 4; .sidemenu{ .menu-header{ color: @menu-header-color; font-size: @menu-font-size; } .menu-link{ text-decoration: none; color: @menu-link-color; font-size: @menu-font-size - @delta-font-size; } } @menu-header-color : black; @menu-link-color : green; @menu-font-size : 16px; .sidemenu{ .menu-header{ color: @menu-header-color; font-size: @menu-font-size; } .menu-link{ text-decoration: none; color: @menu-link-color; } } @menu-header-color : black; @menu-link-color : green; @menu-font-size : 16px; .sidemenu{ .menu-header{ color: @menu-header-color; font-size: @menu-font-size; } .menu-link{ text-decoration: none; color: @menu-link-color; font-size: 12px; } } .sidemenu .menu-header { color: #000000; font-size: 16px; } .sidemenu .menu-link { text-decoration: none; color: #008000; font-size: 12px; }
  • 32.
    Built-ins @menu-header-color : black; @menu-link-color: green; @menu-font-size : 16px; @delta-font-size : @menu-font-size / 4; .sidemenu{ .menu-header{ color: @menu-header-color; font-size: @menu-font-size; } .menu-link{ text-decoration: none; color: @menu-link-color; font-size: @menu-font-size - @delta-font-size; } } .sidemenu { background-color: #404040; } .sidemenu .menu-header { color: #008000; font-size: 16px; } .sidemenu .menu-link { text-decoration: none; color: #00e600; font-size: 12px; } .sidemenu ul { color: #00e600; } @menu-header-color : green; @menu-link-color : lighten(@menu-header-color, 20%); @menu-font-size : 16px; @delta-font-size : @menu-font-size / 4; .sidemenu{ background-color : greyscale(@menu-header-color,@menu-link-color); .menu-header{ color: @menu-header-color; font-size: @menu-font-size; } .menu-link{ text-decoration: none; color: @menu-link-color; font-size: @menu-font-size - @delta-font-size; } ul{ color: @menu-link-color; } }
  • 33.
    Mixins .roundedcorners{ -webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius:10px; } .roundedcorners( @rad : 10px ){ -webkit-border-radius: @rad; -moz-border-radius: @rad; border-radius: @rad; }
  • 34.
    @menu-header-color : green; @menu-link-color: lighten(@menu-header-color, 20%); @menu-font-size : 16px; @delta-font-size : @menu-font-size / 4; .roundedcorners( @rad : 10px ){ -webkit-border-radius: @rad; -moz-border-radius: @rad; border-radius: @rad; } .sidemenu{ background-color : greyscale(@menu-header-color,@menu-link-color); .roundedcorners( 25px ); .menu-header{ color: @menu-header-color; font-size: @menu-font-size; } .menu-link{ text-decoration: none; color: @menu-link-color; font-size: @menu-font-size - @delta-font-size; } ul{ color: @menu-link-color; } } .sidemenu{ background-color : greyscale(@menu-header-color,@menu-link-color); .roundedcorners( 25px ); .menu-header{ color: @menu-header-color; font-size: @menu-font-size; } .menu-link{ text-decoration: none; color: @menu-link-color; font-size: @menu-font-size - @delta-font-size; } ul{ color: @menu-link-color; } } Use Building Blocks
  • 35.
    Use Building Blocks OtherPeople’s http://cl.ly/image/2S0k1q3Q2y2L
  • 36.
    Copyright © 2014APEX Consulting Q& Aroel@apexconsulting.nl http://www.apexconsulting.nl 36
  • 37.