- Static Website
- Structure & Content (HTML) + Presentation (CSS) + Behaviour (JS)
- User Agent & Compatibility
- Programming + Runtime
- Debugging
- API
- Events + Async
- Abstraction(s) + State
- Library & Framework
- DOM tree
- html, head & body
- DOM nodes: root, ancestor, descendent, parent, child, sibling
- element types
- attributes and values
src="http://..."
- block vs inline, as in
p
vsstrong
- DOM API
- manipulation
- binding/unbinding events
- html 5 best practices
- include
meta
to stop browser from zooming in<head>
- conventions
- use double quotes around html attributes
src="http://..."
- IDs and classes in
class="kebab-case"
- use double quotes around html attributes
- use outline/hierarchy:
- h1, h2, ..., ul, li, p, strong
- use semantics:
- nav
- main
- section
- article
- header
- summary
- details
- figure
- aside
- figcaption
- footer
- mark
- time
- use id and classes
- e.g.:
id="site-header"
- e.g.:
class="card product"
- e.g.:
- DON'T
- use only
<div>
and<span>
- use
<br/>
unless poetry - add empty tags just because you need to apply some style
- e.g.:
<div class="clear"></div>
- e.g.:
- use only
- MDN CSS guide
- MDN CSS reference
- W3C CSS Validator
- syntax
- rule
- selector
- declaration: property, value
- shorthand property
- specifity
- pseudo-selector
- :focus
- :hover
- a:active
- a:visited
- :disabled
- :nth-child(number)
- :first-child
- :last-child
- https://cssreference.io/
- and more:
- user agent styles
- reset
- box model
- layout
- typography
- responsive web design
- fluid layout
- mobile first
- transition
- animation
- flexbox (and css grid...)
- demo
position: relative
- used with
top/left
displaces the element (but the original space is still occupied) - establishes an anchor for absoulte descendent
- used with
position: absolute
- element complete leaves the flow
- and looses its natural block ability of being
width 100%
- used with
top/left
, always relative to firstabsolute
ORrelative
ancestor
position: absolute
- used with
top/left
always relative tobody
- used with
.container
- mobile first
- tablet next
- desktop next
- media query syntax
@media (min-width: 768px) { ... more rules ...}
- 9 basic principles of responsive web design
- advanced
- responsive images
- responsive typography
- responsive tables
- see articles in css-tricks
- DOCS
- tutorial
- set display:flex on parent
- parent manages direct children
- properties of the flex parent
justify-content
- across the main axisalign-items
- across the cross axisflex-direction
- row/column/column-reverse/row-reverseflex-wrap
- wrap/nowrap
- properties of the flex children
width: 50%
- percentage of the flex parentwidth: 200px
- static, not managed by the flex parentflex: 1
- 1 out X - where X is total of all the childrenflex: <can grow> <can shrink> <base width>
- advanced (see layout example 1)
-
Strategy 1:
- Demo on codepen
- set the children`s flex grow to 1
- set the children`s flex basis to a number below the column % (e.g. 45% for 2 cols, 30% for 3 cols)
- set the children`s horizontal margin to Ypx
- set the parent`s horizontal margin to -Ypx
- Downside: orphan items will still grow to available space
-
Strategy 2:
- Demo on codepen
- set the children`s width to the exact % (e.g. 50% for 2 cols, 33.33333% for 3 cols)
- set the children`s horizontal padding to Ypx
- set the parent`s horizontal margin to -Ypx
- Downside: because we are using padding on the flex children, we need to move our card class to another child div
- code structure
- reset first
- at least reset the
box-sizing: border-box;
and body'smargin: 0;
- at least reset the
- typography next
- layout
- at least
.container
class
- at least
- components next
- page specifics last
- reset first
- KISS
- avoid px widths,
- avoid heights
- margin bottom + padding top
- DRY
- use hierarchy
<div class="card"><div class="title">...
- target via
.card .title {}
- use composition
- combine classes
class="button primary"
targeted via.button.primary {}
- use cascading
- specifics augment and override generics
#login-button
stronger than.button {}
stronger thana {}
@media (...) { a {} }
stronger thana {}
- use inheritance
- type attributes (font-family, font-size, line-height, color, ...) trickle down from parent to children
- use hierarchy
- semantic:
- semantic css, classes named after what things ARE not what they LOOK LIKE
- e.g.:
.copy
,.site-header
,.copyright
,.email
...
- e.g.:
- semantic css, classes named after what things ARE not what they LOOK LIKE
- clearing floats
overflow: hidden
on the parent- OR
clear: both
on a sibling after the floats
- DO
- short selectors
- e.g.:
.header li
- e.g.:
- short selectors
- DON't
- use
!important
- name classes after presentation
- e.g.:
.green-text {}
- e.g.:
- use
- planning a simple website
- mobile first
- unless desktop only
- sketch first
- identify patterns and components
- html next
- css last
- simplicity
- consistency
- run time environment
- programming
- abstraction
- expression
- statement
- assignment
- declaration
- state
- type
- literal
- variable
- value
- control structure
- conditional
- loop
- algorithm
- debugging
- break-point
- function
- parameter
- scope
- return statement
- function call
- call arguments
- return value
- closure
- call stack
- data structure
- functional programming
- higher order functions
- callback
- context
- prototype
- object oriented programming
- instance
- constructor
- encapsulation
- inheritance
- composition
- number: 1 1.3 Infinity NaN
- boolean: true false
- string: "hello world"
- undefined
- object
- function
var x;
var y = true;
- comparison:
== === != !== > < >= <=
- logical:
&& || !
- logical and short-circuit:
0 && notExecuted
evaluates to0
1 || notExecuted
evaluates to1
- string
+
- arithmetic:
+ - * / % ** ++ --
- bitwise:
& | ^ ~ << >> >>>
- assignment:
= += -= *= /= %= **=
- trenary:
var a = (condition) ? this : orThat
- precedence: PEMDAS
- unary
- typeof
typeof var
- delete
delete var.property
- in
property in obj
- instanceof
var instanceof Constructor
- typeof
- Infinity
- -Infinity
- NaN === NaN
- Number constructor
- Number('123')
- Number('12a')
- Number('')
- Number static
- Number.MAX_VALUE
- Number.isNaN(3 / window)
- Number.isNaN(3 + window)
- Number.isNaN(Number('x'))
- Number.isInteger(3.1)
- funny thing about numbers
- Number.isInteger(3 * (0.1 + 0.2) + 0.1)
- 0.3 === 0.1 + 0.2
- Math.PI
- Math.max(1, 3)
- Math.random()
- Math.abs(-3)
- Math.sign(-3)
- Math.round(10 / 3)
- Math.ceil(10 / 3)
- Math.floor(10 / 3)
- 100 * Math.round(7.03) / 100
- Math.sqrt(10 / 3)
- Math.sin(Math.PI / 2)
- Math.cos(0)
- if (expression) { ... } else if (expression) { ... } else { ... }
- for (initialize; condition; modify ) { ... }
- while (condition) { ... }
- do { ... } while (condition)
- switch (expression) { case "foo": ... ; break; }
- try { ... } catch (err) { ... }
- holds a list of characters
- str.length
- str[0]
- String()
- String static methods
- String.fromCharCode(64)
- methods
- str.split('');
- str.toLowerCase()
- str.substring(0,1)
- str.indexOf('foo')
- str.charCodeAt(1)
- holds a list of values
- var arr = ['1', '2', '3'];
- var arr = new Array();
- arr.length
- arr[index]
- arr[index] = 'foo'
- array static methods
- Array.isArray([])
- array methods
- arr.join()
- arr.pop()
- arr.push('4', '5')
- arr.unshift('foo')
- arr.shift()
- arr.forEach( callback )
- arr.find( callback )
- arr.map( callback )
- arr.reduce( callback )
- arr.filter( callback )
- arr.sort( callback )
- arr.reverse()
- arr.splice(1, 2)
- arr.splice(1, 0, 'foo')
- arr.slice(1, 2)
- holds key value pairs
- var obj = { name: 'foo' }
- obj.name = 'foo'
- obj['name-with-weird-characters'] = 'foo'
- obj[key] = 'foo'
- delete obj.name
- delete obj['name-with-weird-characters']
- delete obj[key]
- for (var key in obj) { ... }
- Object static methods
- Object.keys(obj);
- Object.values(obj);
- function doSomething(param1, param2) { return .... }
- var doSomething = function (...) { ... }
- typeof doSomething // 'function'
- advanced:
- function doFoo() { console.log(arguments) }
- function doFoo() { console.log(this) }
- doFoo.call(otherThis, arg1, arg2)
- doFoo.apply(otherThis, [arg1, arg2])
- dooFoo.name
- window
- window.innerWidth
- window.innerHeight
- window.location.href
- window.alert()
- window.prompt()
- window.scrollBy()
- window.document
- window.onload = function () { ... }
- document.body
- node = document.getElementById('site-header')
- node = document.getElementsByClassName('feature')
- node = document.querySelector('.features .feature')
- nodeList = document.querySelectorAll('.features .feature')
- node.setAttribute('src', 'https://fakeimage.com/image.jpg')
- node.removeAttribute('srcset');
- node.classList.add('active') node.classList.remove('active')
- node.classList.toggle('active')
- node.appendChild(child)
- node.children[0]...
- node.remove()
- node = document.createElement('div')
- node.innerHTML =
'<p>some text</p>'
- node.innerText = 'some text'
- node.addEventListener('click', handleClick);
- node.removeEventListener('click', handleClick);
- function handleClick(event) { ... }
- event.stopPropagation();
- event.preventDefault();
- event.target
- event.currentTarget
- timeoutId = setTimeout(func, 1000)
- clearTimeout(timeoutId)
- intervalId = setInterval(func, 1000)
- clearInterval(intervalId)
- start all files with
'use strict';
docs - write small functions
- start from the return
- tidy code, idented and consistent
- DO
- for literal strings, use
'single quotes'
- one statement per line (don't do
if (foo) { something() }
all in one line) - variables and function parameters use
camelCase
(e.g.:var topScores
) - functions, start with a verb, use
verbCamelCase
(e.g.:function setPosition (x,y) {}
) - for constructors use
PascalCase
(e.g.:function MovingObstacle() {}
)
- for literal strings, use
- DON'T
- use global variables
- repeat yourself
- status
- staging (add)
- commit
- remote (pull, push)
- branch
- merge
- linting
- beautifying