Follow along at
http://taupecat.github.io/sass-102
…which makes it not a programming language. Programming languages require logic, which CSS lacks, with few exceptions.
Like any data type, these can be acted on.
Let's calculate some colors
$states: (
"AL", "DC", "DE", "FL", "GA", "IA", "IL",
"IN", "KY", "LA", "MD", "MI", "MO", "MS",
"NC", "NJ", "NY", "OH", "PA", "SC", "TN",
"VA", "WV"
);
$regions: (
( "DC", "DE", "MD", "NJ", "NY", "PA" ),
( "AL", "FL", "GA", "KY", "LA", "MS", "NC", "SC", "TN", "VA", "WV" ),
( "IA", "IL", "IN", "MI", "MO", "OH" )
);
List indexes start at 1, not 0!
$social: (
"facebook": '\f204',
"twitter": '\f202',
"linkedin": '\f207',
"pinterest": '\f209',
"github": '\f200',
"dribbble": '\f201',
"instagram": '\f215',
"email": '\f410'
);
$mega-social: (
"facebook": ( content: "\f204", coords: 0 0 ),
"twitter": ( content: "\f202", coords: 0 -64px ),
"linkedin": ( content: "\f207", coords: 0 -128px )
);
li.facebook:before {
content: map-get($social, "facebook");
}
li.facebook:before {
content: '\f204';
}
$types: 4
$type-width: 20px
@while $types > 0 {
.while-#{$types} {
width: $type-width + $types;
}
$types: $types - 1
}
.while-4 {
width: 24px;
}
.while-3 {
width: 23px;
}
.while-2 {
width: 22px;
}
.while-1 {
width: 21px;
}
@mixin griddr($cols) {
// do a math here
}
@for $i from 1 through $columns {
.col-#{$i} {
@include griddr($i);
}
}
@for $i from 1 through 9 {
.space-#{$i} {
background-image: url("../images/space/space-#{$i}.jpg");
}
}
.space-1 {
background-image: url("../images/space/space-1.jpg");
}
.space-2 {
background-image: url("../images/space/space-2.jpg");
}
.space-3 {
background-image: url("../images/space/space-3.jpg");
}
etc.
@for $var from 1 through 10 {
// Sass stuff goes here
// Operation includes the number 10
}
@for $var from 1 to 10 {
// Other Sass stuff goes here
// Operation stops after number 9
}
@mixin breakpoint($breakpoint) {
@if $breakpoint == medium {
@media only all and (min-width: 640px) {
@content;
}
} @else if $breakpoint == large {
@media only all and (min-width: 1024px) {
@content;
}
}
}
p {
background-color: rgba(255, 0, 255, 0.2);
@include breakpoint(medium) {
background-color: rgba(255, 255, 0, 0.2);
}
}
p {
background-color: rgba(255, 0, 255, 0.2);
}
@media only all and (min-width: 640px) {
p {
background-color: rgba(255, 255, 0, 0.2);
}
}
Let's use this in the real world.
@each $state in $states {
.#{$state} {
background-image: url("../images/state_infographics/#{$state}.png");
}
}
.AL {
background-image: url("../images/state_infographics/AL.png");
}
.DC {
background-image: url("../images/state_infographics/DC.png");
}
.DE {
background-image: url("../images/state_infographics/DE.png");
}
...
@each $network, $content in $social {
.#{$network} a:before {
content: $content;
}
}
.facebook a:before {
content: '\f204';
}
.twitter a:before {
content: '\f202';
}
.linkedin a:before {
content: '\f207';
}
...
Let's loop through some stuff.