Save 10% off any FITC upcoming event with discount code 'slideshare'. Details at www.fitc.ca
OVERVIEW
Think CSS isn’t important? Or just for girls? Or an afterthought like accessibility or security? Spoiler alert: you’re wrong (about all of those)! CSS has become the gateway drug for most novices and designers-turned-programmer; with preprocessors like LESS and SASS making it easier and easier for web developers to get further down the rabbit hole. In this talk, Kacey will cover a brief history of CSS and where it stands today, the difference between and how to use preprocessors, and where we can likely expect CSS to go in the future. If you’ve ever wondered why UX developers love LESS/SASS, why preprocessors are essential in todays tech stack, then this talk is for you!
OBJECTIVE
Attempt to explain/dismystify CSS as it stands today
TARGET AUDIENCE
Anyone working in, or interested in, web development
ASSUMED AUDIENCE KNOWLEDGE
Little to no web development knowledge needed
FIVE THINGS AUDIENCE MEMBERS WILL LEARN
Why is CSS important
What preprocessors do
Some basic Sass mixins
How preprocessors make your life easier
How CSS is becoming more like JS
2. Hi, I’m Kacey Coughlin
Web Developer, LinkedIn
@kaceykaso
3. Menu:
1.Why is CSS !important?
2.What do preprocessors do?
3.How do preprocessors make your life easier?
4.Basic Sass mixins
5.How CSS is becoming more like JS
6.Where you can learn more…
4. Poll: I prefer to write…
1.) HTML/CSS
2.) Javascript
3.) Neither, backend
forever!
6. When you think of CSS….
“Stylesheet architecture”
“Painting with all the colors of the wind onto jagged mountains in
order to make them look like a bob Ross piece of art”
“Good CSS gives the web a better feel… bad CSS makes me /headde
sk”
“A thing that formats web pages that I totally don't understand”
“Curling into a ball and crying myself to sleep”
7. CSS (Cascading Style Sheet):
A language that describes how to presentation of a
document written in a markup language.
8. Before CSS…
*Possibly the first
website ever, still
works:
http://info.cern.ch/h
ypertext/WWW/The
Project.html
15. CSS3 === Christmas!
Element:not(thing) /* targets elements w/o thing */
Element:first-of-type /* targets the first of this type */
Element:nth-child(n) /* targets every nth child */
Element:nth-of-type(n) /* targets every nth type */
Element[foo*=“bar”] /* targets attr containing “bar” */
Element ~ Element-sibling /* targets any general sibling */
18. CSS Preprocessors
Extends CSS to use variables, operators, functions, and inheritance.
Minifies and concatenates all files into one plain CSS file.
sass-lang.com lesscss.org learnboost.github.io/stylus
20. nav {
ul {
margin: 0;
padding: 0;
list-style: none;
}
li { display: inline-block; }
a {
text-decoration: none;
}
}
nav ul {
margin: 0;
padding: 0;
list-style: none;
}
nav li {
display: inline-block;
}
nav a {
text-decoration: none;
}
Nesting!
35. Minifying (and compiling): CSS
html body,
html * {
font: normal 200 14px/1.5 "Helvetica Neue", "Helvetica", "Arial", sans-serif;
}
body {
background-color: #F0F3F6;
width: 100%;
}
nav.navbar,
.tools-navbar.navbar {
padding: 0 48px;
.navbar-brand {
@include typography($size: large, $style: light, $color: #fff);
letter-spacing: 1px;
}
.navbar-nav,
.navbar-nav > li a > span {
@include typography($size: small, $style: light, $color: #fff);
font-weight: 100;
letter-spacing: 1px;
line-height: 2;
}
.navbar-nav > li .dropdown-menu > li a > span {
color: #000;
}
}
html *,html body{font:normal 200
14px/1.5 "Helvetica
Neue",Helvetica,Arial,sans-
serif}body{background-
color:#F0F3F6;width:100%}.tools-
navbar.navbar,nav.navbar{padding:0
48px}
http://cssminifier.com/
36. Minifying (and compiling): JS
(function ($) {
/**
* @function
* @property {object} jQuery plugin which runs handler function once specified
* element is inserted into the DOM
* @param {function} handler A function to execute at the time when the
* element is inserted
* @param {bool} shouldRunHandlerOnce Optional: if true, handler is unbound
* after its first invocation
* @example $(selector).waitUntilExists(function);
*/
$.fn.waitUntilExists = function (handler, shouldRunHandlerOnce, isChild) {
var found = 'found';
var $this = $(this.selector);
var $elements = $this.not(function () {
return $(this).data(found);
}).each(handler).data(found, true);
if (!isChild) {
(window.waitUntilExists_Intervals = window.waitUntilExists_Intervals ||
{})[this.selector] =
window.setInterval(function () {
$this.waitUntilExists(handler, shouldRunHandlerOnce, true);
}, 500)
;
} else if (shouldRunHandlerOnce && $elements.length) {
window.clearInterval(window.waitUntilExists_Intervals[this.selector]);
}
return $this;
}
}(jQuery));
!function(t){t.fn.waitUntilExists=function(n,i,s){var
e="found",a=t(this.selector),l=a.not(function(){return
t(this).data(e)}).each(n).data(e,!0);return
s?i&&l.length&&window.clearInterval(window.waitUntilE
xists_Intervals[this.selector]):(window.waitUntilExists_Int
ervals=window.waitUntilExists_Intervals||{})[this.selecto
r]=window.setInterval(function(){a.waitUntilExists(n,i,!0)}
,500),a}}(jQuery);
http://jscompress.com/
37. Animations: JS vs CSS
$(’button').hover(function() {
$(this).animate({"color":"#efbe5c","font-size":"52pt"}, 1000); //mouseover
}, function() {
$(this).animate({"color":"#e8a010","font-size":"48pt"}, 1000); //mouseout
});
*Requires Jquery, Jquery Colors, etc
button {
transition: color 1s ease-in-out;
-moz-transition: color 1s ease-in-out;
-webkit-transition: color 1s ease-in-out;
-o-transition: color 1s ease-in-out;
}
button {
@include transition(color, 1s);
}
38. Animations: JS vs CSS*
Jquery and Javascript are not interchangable.
Jquery GSAP CSS
CSS does better with simpler transitions.
JS is better with complicated cubic bezier, 3D, wandering points, etc.
https://css-tricks.com/myth-busting-css-animations-vs-javascript/
http://codepen.io/GreenSock/full/2a53bbbcd47df627f25ed1b74beb407d/
39. Performance
CSS Jquery
• CSS only repaints
what it needs to
• CSS lets the browser
know up front
• Browser cannot
predict with JS
• JS must recalculate
all styles first, then
paint
• Produces visible lag
up front
http://css3.bradshawenterpris
es.com/blog/jquery-vs-css3-
transitions/
40. Functions
$columns: 4;
@for $i from 1 through $columns {
.cols-#{$i} {
width: ((100 / $columns) * $i) * 1%;
}
}
var $columns = 4;
for (var i = 0; i < $columns; i++) {
$(‘.cols-’ + i).css({
‘width’: ((100 / $columns) * i) * 1%)
});
}
CSS JS
42. CSS: The Future!
*CSS4 Spec (Draft): https://drafts.csswg.org/selectors/
Element:matches(param1, param1) /* opposite of :not, takes multiple params */
Element:nth-match(n) /* targets nth matching sibling */
Element:has(param1, param2) /* targets element if it contains params */
Element:dir(rtl) /* targets document language direction */
Element:any-link /* targets any anchor, do not need to specify */
Element:indeterminate /* targets states not checked or unchecked*/
Element:column(thing) /* targets column of element with thing in it */
Element /foo/ Sibling /* targets sibling by element’s attr foo */
Element! > Thing /* targets thing’s parent of type element */
43. HTML -> CSS -> Javascript -> ???
The more you know….
Before CSS3, js was only way to animate (lets ignore Flash). If you didn’t know JS, you were shit out of luck! But now, we can animate with CSS, and what usually tends to be the case now, better understand and slip into JS.
Yes, Javascript (pure) is still king in terms of performance, but that comes with some caviats.