Sass, Compass

Serg Diniovskiy
Serg DiniovskiyHTML Developer um iPark Ventures
Sass, Compass
DIE — Duplication Is
       Evil
.round {
   border-radius: 10px;
   -webkit-border-radius: 10px;
   -moz-border-radius: 10px;
   -o-border-radius: 10px;
   -ms-border-radius: 10px;
   -khtml-border-radius: 10px;
   }
SASS
SCSS                    SASS
header{                 header
  text-align: center;     text-align: center
  h2{                     h2
    font-size: 48px;         font-size: 48px
  }
}




SCSS — Sassy CSS
SASS — Syntactically Awesome Stylesheets
Ни былин,
    ни эпосов,
        ни эпопей.
Телеграммой
    лети,
        строфа!
Воспаленной губой
    припади
        и попей
из реки
    по имени — "Факт".

        В. Маяковский
SCSS — обратная
 совместимость
Каскадность
header                        header {
  background: black             background: black;
  h2                          }
    font:                     header h2 {
      weight: normal            font-weight: normal;
      size: 48px                font-size: 48px;
                              }

a                             a {
    color: blue                 color: blue;
    &:hover                   }
      text-decoration: none   a:hover {
    &::before                   text-decoration: none;
      content: “Sosiska”      }
                              a::before {
                                content: “Sosiska”;
                              }
Переменные
$width: 500px
$height: 400px

.center-absolute
  background: #f2c98a
  width: $width
  height: $height
  position: absolute
  left: 50%
  top: 50%
  margin-top: -($height/2)
  margin-left: -($width/2)
$varclass: cahoona

.big-#{$varclass}
    width: 2em
Примеси
@mixin font($size)
   font: $size Georgia, serif
h1
   +font(48px)
p
   +font(14px)




h1{
   font: 48px Georgia, serif;
}
p{
   font: 14px Georgia, serif;
}
Цвета
$color: #f00

.somebox
    border: 1px solid $color
    box-shadow: 0 0 3px darken($color, 10%),
inset 1px 0 lighten($color, 40%)




.somebox {
  border: 1px solid red;
  box-shadow: 0 0 3px #cc0000, inset 1px 0 #ffcccc;
}
.somebox
    background: rgba(#fff, 0.5)




.somebox {
    background: rgba(255, 255, 255, 0.5);
}
rgb($red, $green, $blue)
rgba($red, $green, $blue, $alpha)
rgba($color, $alpha)
red($color)
green($color)
blue($color)
mix($color-1, $color-2, [$weight])

hsl($hue, $saturation, $lightness)
hsla($hue, $saturation, $lightness, $alpha)
hue($color)
saturation($color)
lightness($color)
adjust-hue($color, $degrees)
lighten($color, $amount)
darken($color, $amount)
saturate($color, $amount)
desaturate($color, $amount)
grayscale($color)
complement($color)
invert($color)

alpha($color) / opacity($color)
rgba($color, $alpha)
opacify($color, $amount) / fade-in($color, $amount)
transparentize($color, $amount) / fade-out($color, $amount)
http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html
@extend
.food
    background-image: url(food-sprite.png)

.food-bacon
    @extend .food
    background-position: 0 -10px
    width: 25px
    height: 10px

.food-pizza
    @extend .food
    background-position: 0 -20px
    width: 45px
    height: 35px
.food, .food-bacon, .food-pizza{
  background-image: url(food-sprite.png);
}

.food-bacon{
  background-position: 0 -10px;
  width: 25px;
  height: 10px;
}

.food-pizza{
  background-position: 0 -20px;
  width: 45px;
  height: 35px;
}
@if, @else
@mixin color($type)
  @if $type == chocolate
    color: brown
  @else if $type == pizza
    color: red
  @else if $type == apple
    color: green
  @else
    color: black

.pizza
  +color(pizza)
@for, @while
@for $i from 1 through 3
  .item-#{$i}
    width: 1em + $i



.item-1 {
  width: 2em;
}

.item-2 {
  width: 3em;
}

.item-3 {
  width: 4em;
}
@each
@each $color in red, green, gray
  .theme-#{$color}
    background: $color




.theme-red{
  background: red;
}

.theme-green{
  background: green;
}

.theme-gray{
  background: gray;
}
@import
master.sass
  @import “main.sass”
  @import “index.sass”
  @import “profile.sass”



master.css
  main.css + index.css + profile.css
Compass
— Nathan Smith
Border-radius
.round
  +border-radius(25px)
.round
   +border-radius(25px)




.round {
   -webkit-border-radius: 25px;
   -moz-border-radius: 25px;
   -o-border-radius: 25px;
   -ms-border-radius: 25px;
   -khtml-border-radius: 25px;
   border-radius: 25px;
   }
Box-shadow
.shadow
   +box-shadow(0 0 4px #ccc)




.shadow {
    -moz-box-shadow: 0 0 4px #cccccc;
    -webkit-box-shadow: 0 0 4px #cccccc;
    -o-box-shadow: 0 0 4px #cccccc;
    box-shadow: 0 0 4px #cccccc;
}
Градиенты
.gradient
    +background-image(linear-gradient(#fff, #ccc 30%, #bbb 70%, #aaa))




.gradient {
    background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #ffffff),
  color-stop(30%, #cccccc), color-stop(70%, #bbbbbb), color-stop(100%, #aaaaaa));
    background-image: -webkit-linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa);
    background-image: -moz-linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa);
    background-image: -o-linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa);
    background-image: -ms-linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa);
    background-image: linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa);
}
.beauty-box
    +border-radius(25px)
    +box-shadow(0 0 4px #ccc)
    +background-image(linear-gradient(#fff, #ccc 30%, #bbb 70%, #aaa))



.beauty-box {
    -webkit-border-radius: 25px;
    -moz-border-radius: 25px;
    -o-border-radius: 25px;
    -ms-border-radius: 25px;
    -khtml-border-radius: 25px;
    border-radius: 25px;
    -moz-box-shadow: 0 0 4px #cccccc;
    -webkit-box-shadow: 0 0 4px #cccccc;
    -o-box-shadow: 0 0 4px #cccccc;
    box-shadow: 0 0 4px #cccccc;
    background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #ffffff),
    color-stop(30%, #cccccc), color-stop(70%, #bbbbbb), color-stop(100%, #aaaaaa));
    background-image: -webkit-linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa);
    background-image: -moz-linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa);
    background-image: -o-linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa);
    background-image: -ms-linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa);
    background-image: linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa);
}
Еще примеси
Background Clip
Background Origin
Background Size
Box
Box Sizing
Columns
Clearfix
Font Face
Inline Block
Opacity
Transition
Transform
http://compass-style.org/reference/compass/css3/
Спрайты
fb.png   vk.png   twi.png




$sprite: sprite-map("ico/*.png")

.fb
  background: sprite($sprite, fb)
.vk
  background: sprite($sprite, vk)
.twi
  background: sprite($sprite, twi)
ico-s2e5fe71d31.png



.fb {
  background: url('images/ico-s2e5fe71d31.png') 0 0px no-repeat;
}
.vk {
  background: url('images/ico-s2e5fe71d31.png') 0 -41px no-repeat;
}
.twi {
  background: url('images/ico-s2e5fe71d31.png') 0 -82px no-repeat;
}
.basebox
  background: inline-image("pic.png")




.basebox {
  background: url('data:image/png;base64,1UcAAA...AASUVORK5CYII=');
}
Config.rb

# You can select your preferred output style here (can be overridden via the
command line):
# output_style = :expanded or :nested or :compact or :compressed



output_style = :compressed
Установка
Windows   1. http://rubyinstaller.org/downloads/
          2. gem install haml
          3. gem install haml/edge
          4. gem install compass

Mac       1. gem install haml
          2. gem install haml/edge
          3. gem install compass

Linux     1. sudo apt-get install ruby
          2. gem install haml
          3. gem install haml/edge
          4. gem install compass
Как это работает
compass create <projectname> - создает
compass-проект

compass watch - следит за изменениями в
sass-файлах и сразу компилирует их в css
Что почитать
http://sass-lang.com/
http://compass-style.org/
http://chriseppstein.github.com/
http://nex-3.com/
http://thesassway.com/
Спасибо
Вопросы?

                    @lazio_od
           sd@evilmartians.com
           www.evilmartians.ru
           Дыниовский Сергей
1 von 48

Más contenido relacionado

Was ist angesagt?(20)

Learn to Love CSS3 [English]Learn to Love CSS3 [English]
Learn to Love CSS3 [English]
ThemePartner993 views
Big Design Conference: CSS3 Big Design Conference: CSS3
Big Design Conference: CSS3
Wynn Netherland1.7K views
Xlrays online web tutorialsXlrays online web tutorials
Xlrays online web tutorials
Yogesh Gupta492 views
Demystifying CSS & WordPressDemystifying CSS & WordPress
Demystifying CSS & WordPress
Justin Carmony1.8K views
Keep calm and let's play CSS3Keep calm and let's play CSS3
Keep calm and let's play CSS3
A2 Comunicação473 views
Finding your way with Sass+CompassFinding your way with Sass+Compass
Finding your way with Sass+Compass
drywallbmb1.3K views
Theme 23Theme 23
Theme 23
bellaandzendaya291 views
Ch1(introduction to php)Ch1(introduction to php)
Ch1(introduction to php)
Chhom Karath387 views
EverestEverest
Everest
Anang Febrianto768 views
Landing Pages 101Landing Pages 101
Landing Pages 101
Celeste Horgan160 views
JSON and the APInautsJSON and the APInauts
JSON and the APInauts
Wynn Netherland5.1K views
Confoo: The New CSS LayoutConfoo: The New CSS Layout
Confoo: The New CSS Layout
Rachel Andrew1.2K views
WsomdpWsomdp
Wsomdp
riahialae1.5K views

Destacado(20)

Agile CSS development with Compass and SassAgile CSS development with Compass and Sass
Agile CSS development with Compass and Sass
Andrea Verlicchi1.2K views
805 15-kevin805 15-kevin
805 15-kevin
tydkhlw78100150 views
Road safetyRoad safety
Road safety
Mirmike559 views
RSS와 SNS를 활용한 마케팅RSS와 SNS를 활용한 마케팅
RSS와 SNS를 활용한 마케팅
은창 이1.1K views
HalloweenHalloween
Halloween
oscar324134 views
PresentationPresentation
Presentation
Diana Rashidova117 views
Dumpster divingDumpster diving
Dumpster diving
Khalid Alqammash469 views
Pattern based designPattern based design
Pattern based design
Utkarsh Verma669 views
2011 CMA Festival Championship2011 CMA Festival Championship
2011 CMA Festival Championship
Daniel Pesek180 views
Fotografias motos chopperFotografias motos chopper
Fotografias motos chopper
ediadri8556 views
Arch. maria rosaria_marsicoArch. maria rosaria_marsico
Arch. maria rosaria_marsico
Abdelkader Benyoucef756 views
tugas 7tugas 7
tugas 7
Dyah Mulhayail201 views
Tugas ke 1Tugas ke 1
Tugas ke 1
Dyah Mulhayail162 views
Mp4 RecoveryMp4 Recovery
Mp4 Recovery
Tobycretin427 views
Tugas ke 5Tugas ke 5
Tugas ke 5
Dyah Mulhayail149 views
기업의 마케팅 트위터기업의 마케팅 트위터
기업의 마케팅 트위터
은창 이331 views
Solomon rprc7e dyn10Solomon rprc7e dyn10
Solomon rprc7e dyn10
Susie Pryor441 views
Tugas ke 6Tugas ke 6
Tugas ke 6
Dyah Mulhayail209 views

Similar a Sass, Compass

FCIP SASS TalkFCIP SASS Talk
FCIP SASS TalkChris Schneider
715 views36 Folien
Css 2Css 2
Css 2Abdel Suarez
119 views1 Folie
CssCss
CssAbdel Suarez
249 views1 Folie
Css 3Css 3
Css 3Abdel Suarez
1.5K views5 Folien

Similar a Sass, Compass(20)

CSS3 is Not Magic Pixie DustCSS3 is Not Magic Pixie Dust
CSS3 is Not Magic Pixie Dust
Kyle Adams894 views
FCIP SASS TalkFCIP SASS Talk
FCIP SASS Talk
Chris Schneider715 views
Wrangling the CSS Beast  with SassWrangling the CSS Beast  with Sass
Wrangling the CSS Beast with Sass
Rob Friesel1.4K views
Css 2Css 2
Css 2
Abdel Suarez119 views
CssCss
Css
Abdel Suarez249 views
Css 3Css 3
Css 3
Abdel Suarez1.5K views
HTML&CSS 5 - Intermediate CSS (2/2)HTML&CSS 5 - Intermediate CSS (2/2)
HTML&CSS 5 - Intermediate CSS (2/2)
Dinis Correia1.1K views
Work and play with SASS & CompassWork and play with SASS & Compass
Work and play with SASS & Compass
Andreas Dantz1.4K views
Using Sass - Building on CSSUsing Sass - Building on CSS
Using Sass - Building on CSS
Sayanee Basu1K views
Preprocessor presentationPreprocessor presentation
Preprocessor presentation
Mario Noble1.3K views
Rapid PrototypingRapid Prototyping
Rapid Prototyping
Even Wu1.4K views
Css3 process barCss3 process bar
Css3 process bar
Mirza Arslan383 views
Css3 process barCss3 process bar
Css3 process bar
Mirza Arslan99 views
Css3 process barCss3 process bar
Css3 process bar
Mirza Arslan247 views
Save time by using SASS/SCSSSave time by using SASS/SCSS
Save time by using SASS/SCSS
Berit Hlubek3.3K views
Sass compassSass compass
Sass compass
Nick Cooley1.3K views

Sass, Compass

  • 3. .round { border-radius: 10px; -webkit-border-radius: 10px; -moz-border-radius: 10px; -o-border-radius: 10px; -ms-border-radius: 10px; -khtml-border-radius: 10px; }
  • 5. SCSS SASS header{ header text-align: center; text-align: center h2{ h2 font-size: 48px; font-size: 48px } } SCSS — Sassy CSS SASS — Syntactically Awesome Stylesheets
  • 6. Ни былин, ни эпосов, ни эпопей. Телеграммой лети, строфа! Воспаленной губой припади и попей из реки по имени — "Факт". В. Маяковский
  • 7. SCSS — обратная совместимость
  • 9. header header { background: black background: black; h2 } font: header h2 { weight: normal font-weight: normal; size: 48px font-size: 48px; } a a { color: blue color: blue; &:hover } text-decoration: none a:hover { &::before text-decoration: none; content: “Sosiska” } a::before { content: “Sosiska”; }
  • 11. $width: 500px $height: 400px .center-absolute background: #f2c98a width: $width height: $height position: absolute left: 50% top: 50% margin-top: -($height/2) margin-left: -($width/2)
  • 14. @mixin font($size) font: $size Georgia, serif h1 +font(48px) p +font(14px) h1{ font: 48px Georgia, serif; } p{ font: 14px Georgia, serif; }
  • 16. $color: #f00 .somebox border: 1px solid $color box-shadow: 0 0 3px darken($color, 10%), inset 1px 0 lighten($color, 40%) .somebox { border: 1px solid red; box-shadow: 0 0 3px #cc0000, inset 1px 0 #ffcccc; }
  • 17. .somebox background: rgba(#fff, 0.5) .somebox { background: rgba(255, 255, 255, 0.5); }
  • 18. rgb($red, $green, $blue) rgba($red, $green, $blue, $alpha) rgba($color, $alpha) red($color) green($color) blue($color) mix($color-1, $color-2, [$weight]) hsl($hue, $saturation, $lightness) hsla($hue, $saturation, $lightness, $alpha) hue($color) saturation($color) lightness($color) adjust-hue($color, $degrees) lighten($color, $amount) darken($color, $amount) saturate($color, $amount) desaturate($color, $amount) grayscale($color) complement($color) invert($color) alpha($color) / opacity($color) rgba($color, $alpha) opacify($color, $amount) / fade-in($color, $amount) transparentize($color, $amount) / fade-out($color, $amount)
  • 21. .food background-image: url(food-sprite.png) .food-bacon @extend .food background-position: 0 -10px width: 25px height: 10px .food-pizza @extend .food background-position: 0 -20px width: 45px height: 35px
  • 22. .food, .food-bacon, .food-pizza{ background-image: url(food-sprite.png); } .food-bacon{ background-position: 0 -10px; width: 25px; height: 10px; } .food-pizza{ background-position: 0 -20px; width: 45px; height: 35px; }
  • 24. @mixin color($type) @if $type == chocolate color: brown @else if $type == pizza color: red @else if $type == apple color: green @else color: black .pizza +color(pizza)
  • 26. @for $i from 1 through 3 .item-#{$i} width: 1em + $i .item-1 { width: 2em; } .item-2 { width: 3em; } .item-3 { width: 4em; }
  • 27. @each
  • 28. @each $color in red, green, gray .theme-#{$color} background: $color .theme-red{ background: red; } .theme-green{ background: green; } .theme-gray{ background: gray; }
  • 30. master.sass @import “main.sass” @import “index.sass” @import “profile.sass” master.css main.css + index.css + profile.css
  • 34. .round +border-radius(25px) .round { -webkit-border-radius: 25px; -moz-border-radius: 25px; -o-border-radius: 25px; -ms-border-radius: 25px; -khtml-border-radius: 25px; border-radius: 25px; }
  • 35. Box-shadow .shadow   +box-shadow(0 0 4px #ccc) .shadow {   -moz-box-shadow: 0 0 4px #cccccc;   -webkit-box-shadow: 0 0 4px #cccccc;   -o-box-shadow: 0 0 4px #cccccc;   box-shadow: 0 0 4px #cccccc; }
  • 36. Градиенты .gradient   +background-image(linear-gradient(#fff, #ccc 30%, #bbb 70%, #aaa)) .gradient { background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #ffffff), color-stop(30%, #cccccc), color-stop(70%, #bbbbbb), color-stop(100%, #aaaaaa)); background-image: -webkit-linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa); background-image: -moz-linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa); background-image: -o-linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa); background-image: -ms-linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa); background-image: linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa); }
  • 37. .beauty-box +border-radius(25px) +box-shadow(0 0 4px #ccc) +background-image(linear-gradient(#fff, #ccc 30%, #bbb 70%, #aaa)) .beauty-box { -webkit-border-radius: 25px; -moz-border-radius: 25px; -o-border-radius: 25px; -ms-border-radius: 25px; -khtml-border-radius: 25px; border-radius: 25px; -moz-box-shadow: 0 0 4px #cccccc; -webkit-box-shadow: 0 0 4px #cccccc; -o-box-shadow: 0 0 4px #cccccc; box-shadow: 0 0 4px #cccccc; background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #ffffff), color-stop(30%, #cccccc), color-stop(70%, #bbbbbb), color-stop(100%, #aaaaaa)); background-image: -webkit-linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa); background-image: -moz-linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa); background-image: -o-linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa); background-image: -ms-linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa); background-image: linear-gradient(#ffffff, #cccccc 30%, #bbbbbb 70%, #aaaaaa); }
  • 38. Еще примеси Background Clip Background Origin Background Size Box Box Sizing Columns Clearfix Font Face Inline Block Opacity Transition Transform
  • 41. fb.png vk.png twi.png $sprite: sprite-map("ico/*.png") .fb background: sprite($sprite, fb) .vk background: sprite($sprite, vk) .twi background: sprite($sprite, twi)
  • 42. ico-s2e5fe71d31.png .fb { background: url('images/ico-s2e5fe71d31.png') 0 0px no-repeat; } .vk { background: url('images/ico-s2e5fe71d31.png') 0 -41px no-repeat; } .twi { background: url('images/ico-s2e5fe71d31.png') 0 -82px no-repeat; }
  • 43. .basebox background: inline-image("pic.png") .basebox { background: url('data:image/png;base64,1UcAAA...AASUVORK5CYII='); }
  • 44. Config.rb # You can select your preferred output style here (can be overridden via the command line): # output_style = :expanded or :nested or :compact or :compressed output_style = :compressed
  • 45. Установка Windows 1. http://rubyinstaller.org/downloads/ 2. gem install haml 3. gem install haml/edge 4. gem install compass Mac 1. gem install haml 2. gem install haml/edge 3. gem install compass Linux 1. sudo apt-get install ruby 2. gem install haml 3. gem install haml/edge 4. gem install compass
  • 46. Как это работает compass create <projectname> - создает compass-проект compass watch - следит за изменениями в sass-файлах и сразу компилирует их в css
  • 48. Спасибо Вопросы? @lazio_od sd@evilmartians.com www.evilmartians.ru Дыниовский Сергей

Hinweis der Redaktion

  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
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n