csc309 winter 2016 lecture 2 - university of torontoylzhang/csc309w16/files/lec02-css.pdf ·...
TRANSCRIPT
![Page 1: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/1.jpg)
CSC309 Winter 2016
Lecture 2Larry Zhang
1
![Page 2: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/2.jpg)
Announcements
➔ Assignment 1 is out, due Jan 25, 10pm. Start Early!➔ Work in groups of 2, make groups on MarkUs.➔ Make sure you can login to MarkUs, if not let me know.
➔ Tutorial 1 this Wednesday, very important!➔ You will setup your personal web space on cs.utm servers.➔ You will exercise with HTML and CSS, which is what A1 is about.➔ Consider go to the 6-7pm section, fewer people, more help.➔ If you are from StG, email me your UTORID so I can create account for you
on cs.utm servers.2
![Page 3: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/3.jpg)
Cascading Style Sheets
3
![Page 4: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/4.jpg)
Why CSS?
➔ For each element that we have in the HTML file, we want to define some style for it.◆ size◆ color◆ position◆ margin◆ alignment◆ etc....
4
![Page 5: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/5.jpg)
The primitive way of styling
What’s bad about this?5
![Page 6: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/6.jpg)
Why CSS
We would like to decouple the code that describes
➔ What information is displayed➔ How the information is displayed
HTML file
CSS file
➔ Because of the separation, one CSS file can control the style of multiple HTML files.
➔ Decoupling is an important idea in software engineering!6
![Page 7: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/7.jpg)
Using a stylesheet file, e.g., “style.css”
<head>…<link href=”style.css” type=”text/css” rel=”stylesheet” />…</head>
One HTML file can include multiple stylesheets.
What if have conflicts? Good question. Will talk about it later.
7
![Page 8: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/8.jpg)
Can also embed into HTML file
Avoid using in general. Only for quick-and-dirty tests.
8
![Page 10: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/10.jpg)
Basic CSS Rule Syntax
selector {
property: value;
property: value;
...
property: value;
}
The HTML elements selected by the selector have style define by all the property-value pairs.
10
![Page 11: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/11.jpg)
Selectors
11
![Page 12: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/12.jpg)
Select all elements of a kind
p {
font-size:100px;
color:red;
font-weight:bold;
} All <p> elements in HTML have font size 100px, red color and are boldface.
12
![Page 13: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/13.jpg)
You can group different selectors (use comma)
p, h1 {
color:red;
}
All <p> and <h1> elements in HTML have red colour.
13
![Page 14: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/14.jpg)
Select A inside B (use space)
<p>The red paragraph</p>
<div>
<p>I want to be blue!</p>
</div>
div p {
color:blue;
}
All <p> inside <div> have blue colour.
14
![Page 15: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/15.jpg)
Care about immediate parent (use “>”)
<div>
<span><p>I won’t turn blue!</p></span>
</div>
<div>
<p>I am blue.</p>
</div>
div > p {
color:blue;
}
select <p> whose immediate parent is a <div>
15
![Page 16: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/16.jpg)
Select according attribute (use [attr])
a[target] {
color:blue;
}
<a target=”_blank” href=”x.html”>I’m blue.</a>
<a href=”x.html”>I don’t turn blue</a>
select <a> who has “target” attribute
16
![Page 17: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/17.jpg)
Select elements under some “special state”
a:hover {
color:blue;
}
<a> turns blue when hovered over by mouse.
17
![Page 18: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/18.jpg)
Pseudo classes
18
![Page 19: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/19.jpg)
How to select this?
<p>A normal paragraph</p>
<p>I want to be different!</p>
Hard to find a selector that distinguishes these two.
The ugly way
<p>A normal paragraph</p>
<p style=”color:blue;”>I want to be different!</p>19
![Page 20: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/20.jpg)
The better way: use id or class attributes
<p>A normal paragraph</p>
<p id=”different”>I want to be different!</p>
#different {
color:blue;
}
Select the element with id “different”
20
![Page 21: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/21.jpg)
Use class
<p>A normal paragraph</p>
<p class=”different”>I want to be different!</p>
.different {
color:blue;
}
Select the element with class “different”21
![Page 22: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/22.jpg)
id vs class
➔ id must be unique, i.e., one id can only be used once by a single element.
➔ one class name can be used by multiple elements
22
![Page 23: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/23.jpg)
* {
color:blue;
}
p * {
color:blue;
}
23
![Page 24: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/24.jpg)
Full list of CSS selectors
➔ http://www.w3schools.com/cssref/css_selectors.asp
CSS selector (fun) exercises
➔ http://flukeout.github.io/
24
![Page 25: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/25.jpg)
Takeaway: what are the pros of using selectors compared to
➔ one selector can select multiple elements, so don’t need write the same style multiple times.
➔ one element can be of multiple class and combine multiple styles
➔ In general, it is better organized and more flexible
➔ Javascript works well with selectors, too.
25
![Page 26: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/26.jpg)
Cascading Style Sheets
What is cascading about?
26
![Page 27: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/27.jpg)
Cascading
➔ More than one stylesheet rules could be applied to an HTML element
➔ We need a way to determine which rule actually has effect.
➔ The general rule is to cascade down from more general rules to more specific rules, i.e., the more specific rule is chosen.
27
![Page 28: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/28.jpg)
Example
<div>
<p>What’s my colour?</p>
</div>p {
color:red;
}
div p {
color:blue;
}This rule is more specific, so the colour is blue.
28
![Page 29: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/29.jpg)
Cascading: more details➔ Later rules override earlier rules (with everything else being equal)
➔ Closer rules override farther rules
◆ inline rules override…
◆ rules embedded in the head, which overrides
◆ rules defined in external stylesheet
➔ more specific rules override more general rules
➔ an element inherits the style of its container
➔ The exact calculation: http://www.blooberry.com/indexdot/css/topics/cascade.htm
➔ Your code should be so simple and clear that no complicated calculation is need to determine which one overrides.
29
![Page 30: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/30.jpg)
selector {
property: value;
property: value;
...
property: value;
}
We’re done talking about selectors
Let’s talk about properties and values.
30
![Page 31: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/31.jpg)
the style properties that you can set
31
![Page 32: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/32.jpg)
colours
32
![Page 33: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/33.jpg)
Specifying colours
33
![Page 34: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/34.jpg)
Fonts
Full list of font properties: http://www.w3schools.com/css/css_font.asp
34
![Page 35: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/35.jpg)
Font family
35
![Page 36: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/36.jpg)
Font family
36
![Page 37: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/37.jpg)
Font size
37
![Page 38: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/38.jpg)
Font sizeUsing em is recommended by W3C
38
![Page 39: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/39.jpg)
font-weight, font-style
39
![Page 40: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/40.jpg)
CSS properties for text
Full list of text properties: http://www.w3schools.com/css/css_text.asp
40
![Page 41: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/41.jpg)
text-align
41
![Page 42: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/42.jpg)
text-decoration
42
![Page 43: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/43.jpg)
CSS properties for background
43
![Page 44: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/44.jpg)
background-image
44
![Page 45: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/45.jpg)
background-repeat
45
![Page 46: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/46.jpg)
background-position
46
![Page 47: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/47.jpg)
Just look it up here when neededhttp://www.w3schools.com/css/default.asp
47
![Page 48: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/48.jpg)
Page Layout with CSS
48
![Page 49: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/49.jpg)
The CSS Box Model
49
![Page 50: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/50.jpg)
The CSS Box Model: more details
50
![Page 51: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/51.jpg)
Related properties of the box model
border: 5px solid red;
margin //for all 4 sides
margin-left
margin-right
margin-top
margin-bottom
padding //for all 4 sides
padding-left
padding-right
padding-top
padding-bottom
width, height: note this is only for the content part, the real width/height of the whole box is more than the defined value (+padding+border+margin)
51
![Page 52: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/52.jpg)
More about width
width changes with browser size
limit the range of change
52
![Page 53: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/53.jpg)
Float
53
![Page 54: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/54.jpg)
The normal document flow
block elements
inline elements
54
![Page 55: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/55.jpg)
The normal document flow: with both
55
![Page 56: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/56.jpg)
Float
56
![Page 57: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/57.jpg)
document flow with float
57
![Page 58: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/58.jpg)
clear
disallows the floating element to overlap with the element that “clears”
58
![Page 59: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/59.jpg)
document flow with clear
59
![Page 60: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/60.jpg)
common bug: float with no width
60
![Page 61: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/61.jpg)
common bug: container too short
61
![Page 62: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/62.jpg)
fix it: using overflow: hidden (or auto)
62
![Page 63: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/63.jpg)
Multi-column layout
63
![Page 64: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/64.jpg)
Position
64
![Page 65: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/65.jpg)
The position property
65
![Page 66: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/66.jpg)
MUST READ & TRY
great tutorial with positioning examples
http://www.barelyfitz.com/screencast/html-training/css/positioning/
66
![Page 67: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/67.jpg)
display and visibility
67
![Page 68: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/68.jpg)
display
68
![Page 69: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/69.jpg)
visibility
69
![Page 70: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/70.jpg)
display:none; vs visibility:hidden;
➔ display:none; makes an element take NO space➔ visibility:hidden; still takes the space but just you can’t see it
div1
div3
div3
div1
70
![Page 71: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/71.jpg)
Takeaway: box model, doc flow...
Before you learn these things, you may have had your CSS kind-of working by try-change-it-and-see-what-happens (change margin or padding? don’t care), that typically leads to broken ugly layouts, without you realizing it.
Now you learned these things, you should do everything in the principled way.
71
![Page 72: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/72.jpg)
CSS3
the latest standard of CSS
72
![Page 73: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/73.jpg)
CSS3
➔ CSS3 is completely backward-compatible with old version of CSS, and added a bunch of new features, such as
◆ round corners
◆ gradients
◆ shadows
◆ animation
◆ media queries
73
![Page 74: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/74.jpg)
Rounded corner
We used to have to do this:
-moz-border-radius: 10px 5px;
-webkit-border-top-left-radius: 10px;
-webkit-border-top-right-radius: 5px;
-webkit-border-bottom-right-radius: 10px;
-webkit-border-bottom-left-radius: 5px;
border-radius: 10px 5px;
Now we do this
border-radius: 10px 5px;
74
![Page 75: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/75.jpg)
Media Query
Useful for responsive design, i.e., change the page style dynamically according to the screen size.
For example:
demo link: http://www.w3schools.com/css/css3_mediaqueries.asp75
![Page 76: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/76.jpg)
CSS3 Animation
No need of Javascript.
Demo
https://daneden.github.io/animate.css/
76
![Page 77: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/77.jpg)
77
![Page 78: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/78.jpg)
Assignment 1
➔ One HTML, two stylesheets
78
![Page 79: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/79.jpg)
Assignment 1
➔ make sure to satisfy all the requirement➔ try to make it good-looking➔ can add additional features, without violating any requirements➔ Ask me whenever there is something unclear.
➔ For source code management, the department can only do SVN right now, which is not good
➔ So, recommendation: use Bitbucket (http://bitbucket.org) to create a shared GIT or Mercurial repository with your partner.
➔ Make you project PRIVATE!79
![Page 80: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/80.jpg)
The minimalist GIT tutorial
80
GIT SVN
git clone <repo URL> svn checkout <repo URL>
git pull origin master svn update
git add <filename> svn add <filename>
git commit -am “<log text>”
git push origin mastersvn commit -m “<log text>”
git status svn status
The GIT book: https://git-scm.com/book/en/v2Why you should use git:https://www.youtube.com/watch?v=4XpnKHJAok8
![Page 81: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/81.jpg)
Google Font
Easy way to get fancy fonts.
https://www.google.com/fonts
You can use it for Assignment 1.
81
![Page 82: CSC309 Winter 2016 Lecture 2 - University of Torontoylzhang/csc309w16/files/lec02-css.pdf · font-size:100px; color:red; font-weight: ... The general rule is to cascade down from](https://reader031.vdocument.in/reader031/viewer/2022020411/5aade7257f8b9a59478b5ffc/html5/thumbnails/82.jpg)
Today we learned
➔ CSS
Next week:
➔ Javascript
82