betwixt code and music

The Iron Yard - Day 05

Day 05 - SASS part2

Something learned very early in development or programming is the beautiful phrase "Don't Repeat Yourself" - usually referred to as DRY. Learning about Sass at The Iron Yard, on my own a bit, and at a local Austin meet-up was a great way to work it in to my homework project. The group ATXSass had the great speakers Abby Larner and Una Kravets. This was a fun presentation about the basics of the tool. Also, having gone to this meetup in ATX and several meetups in the my hometown of Dallas (woot!), I can easily say that the tech scene thrives on getting together. There is something magical about finally meeting the people that dance across your Twitter account as pixels... They are really real people, turns out!

Some more thoughts about Sass, the beneficial CSS pre-compiler follow the nice sassy picture.

This handy-dandy feature behaves like a variable but lets you put in more lines of code. If you are familiar with a formal programming language like C++ or JavaScript, then you might consider this to act like a function.

At the top of your code (or really anywhere
before you need it) add a mixin by including this code:
@ mixin link() {
background-color: pink;
color: white;

This means that we want to use the visual configuration of white text on a pink background - and we are likely going to use it more than once in the body of the code. Perhaps this is useful if a person is dealing with several sections that will have the same formatting.

When the mixin is needed in the code (after it has been declared!), then just use this to include it:
@include link();

Now...a great reason I saw to use this in code. It is becoming accepted to use the measurement "em" when dealing with font size. This is based on the current font size or approximately 16 pixels. (Pixels are points of light on the screen) - If you have a picture that is 800x600, then you are dealing with 800 pixels horizontally and 600 pixels vertically). Using a "em"s is smart when considering that the end user will likely increase the size of the content (think smartphone or tablet). This means that the font size will scale appropriately when the entire page is "zoomed in".

Here is a snippet of code that will allow us to insert font sizes as the "em" measurement, but also provide a measurement in pixels.
@mixin font($em) {
font-size: ($em*16) + px;
font-size: ($em) + em;

Note: not all browsers on all devices support all of the things written, so it is a good idea to provide measures like this to shore up your code to be backwards-compatible to older browsers).

The perceptive student will note the $em is a variable. Mixins can include variables, which makes this a very powerful tool! This can be called from within the code like this:
footer {
color: blue;
font-weight: bold;
@include font(4);

There is SO MUCH MORE to learning Sass, but this is a good primer for getting started. I know that I am learning a ton more about how to use it to shorten my code and to keep it DRY!

The Iron Yard - Day 04

Day 04 - SASS

image courtesy of sass-lang.com

Whoa, baby, this stuff is cool. Syntactically Awesome Style Sheets or, SASS, makes writing CSS a much easier process. There are two versions. Hamburger A is Sass, Hamburger B is SCSS.

We learned about the SCSS flavor in class today at
The Iron Yard. Sass lets a developer write complex CSS in a simplified way using various patterns.

This makes the HTML and CSS look more similar in structure. The code snippet below has a nav tag (which functions as a div container, just semantically different) which contains an anchor tag. The SCSS lets a developer nest a CSS property inside of other ones. SCSS will automatically compile to stock CSS in another file. As a visual person, this is extremely helpful because I can now easily see which tags are inside of others as opposed to searching through hundreds of CSS tags.

This is generated:
nav {
background-color: #fff;
padding: 0.5em 0;

a {
margin: 0 1em;
color: #565D64;

Which puts this into the stock CSS file:
nav {
background-color: #fff;
padding: 0.5em 0; }
nav a {
margin: 0 1em;
color: #565D64; }

And you might be thinking, "Big whoop. That is just as easy to write in CSS!" Well, you might be right, pardner, but as you mentally extend this to a larger framework of a site, it becomes easy to imagine the usefulness of this here technique.

SCSS allows defined variables to be used throughout the code. I learned about some scenarios today which made this seem like the greatest thing since the wristwatch. For example...

You are a designer (or an indy developer) dealing with three different main colors on the site you are building. You apply the variable method to your colors like so:
$primaryColor: #bada55;

And you apply it to code like this:
a {
color: red;
background-color: pink;

You are building your site and all is fine until one afternoon your client says that she really wants a
deeper shade of green. No sweat if you used the $primaryColor variable. Just go switch the variable at the top of the file and all of the colors switch throughout the layout.

Thankfully, there was also a meetup for ATXSass the very same day that I learned about Sass. What a break! I headed downtown to the
Capital Factory and learned more about Sass from Abby Larner and Una Kravets. More to come about Sass, so stay tuned.