The way we've managed CSS layouts has evolved over the years. In chronological order:
<table>
tag, you can create columns and rows. This (sort of) allows you to manage complex layouts, but it's really clunky and has some limitationsfloat:left;
or float:right;
pulls elements out of the layout flow. This has been used to create column layouts, but floating has some idiosyncrasies that require proactive management. Floated elements must be "cleared", and this can cause problems.display:flex;
is the modern way to manage complex layouts with CSS. It allows you to flexibly size child elements using some special CSS properties such as flex
. You can find more info at MDN.CSS selectors are how you get things on the page to style them in your CSS. There are a few basic ways to do this:
a { color: red; }
.danger { color: red; }
#warning-text { color: red; }
Remember:
Select on multiple things on a single element by chaining selectors together without a space, for example: a.danger.btn { color: red; }
You can select nested elements by putting a space between selectors. For example: header a
selects all the <a>
tags in the header.
Some rules of thumb when nesting CSS selectors:
In programming languages, information is stored in things called variables.
in Javascript variables are created using the keyword var
. For example: var x = 1;
Variables can store different types of data, for example:
;
)var
. You can't use them as variable names.*/+-@"
forExample
In the above example (var x = 1;
), we call the equals sign (=
) the "operator". The operator =
assigns a value to a variable. The above example assigns the value 1
to the variable x
.
There are other operators used to manipulate values, for example: +
, -
, *
, etc.
Functions fundamentally have three parts:
undefined
.For example:
function sum(a, b) {
var result = a + b;
return result;
}
Functions are called with parentheses, for example, the following returns the number 5:
sum(2, 3);
Javascript and the browser provide you with a bunch of functions you can use to do things. You can find a complete list at MDN. Some examples (try them out!):
parseInt
alert
prompt