1. Realize web layout…
2. Learn CSS for Layout✻
3. Make it RWD!!
Instructions
Slide 5
Slide 5 text
1. About Web Layout…
Wait, what is layout!?
Slide 6
Slide 6 text
1. About Layout…
“Put each element
at each place you want.”
Slide 7
Slide 7 text
1. Web Layout…
Web Layout!
Not Web Layout
Web layout is like Tetris, we pile elements one by one.
Slide 8
Slide 8 text
1. About Layout…
In python, we have error messages
It help us diagnose problems.
zzz
Slide 9
Slide 9 text
1. Ideal web Layout…
But in “CSS”,
we do not have error messages.
So…
budy {
funt-size: 15qx;
buger-radius: 5px
}
“You didn’t see anything. “
Everything is
default!
Slide 10
Slide 10 text
1. Real World Web Layout…
Image: 1, 2
It’s a little bit hard to trace the bug…
Slide 11
Slide 11 text
1. About Web Layout…
If you want to move something to some place, you need to
know its attributes.
Display
Position
Margin Padding
Center
Box
Slide 12
Slide 12 text
2. CSS For Layout ✻✻
Reset: The first step.
width & height: auto & %
Display: “Where the magic happens”
Position: How to put the element??
Flex & Grid: OMG It’s so useful!!!
or bug!
Slide 13
Slide 13 text
2.1. Reset CSS
Browsers are enthusiastic, they will put some different default
CSS style.
More
You’re welcome~
Like this
and this one
Slide 14
Slide 14 text
2.1. Reset CSS
So we need to reset our CSS to keep UI consistency among browsers.
We can also use complex reset code: Link
Or you can try normalize CSS.
2.2.3 height: auto & 100%
height: auto; (black border)
height: 100%;
height: 100%
depend upon
the height of its parent
(parent -> gray border)
height: auto; (default)
depend upon
the height of its children
(children -> green border)
Slide 18
Slide 18 text
2. CSS For Layout
Reset: The first step.
width & height: auto & %
Display: Where the magic happens
Position: How to put the element??
Flex & Grid: OMG It’s so useful!!!
or bug!
v
v
Slide 19
Slide 19 text
2.3 display - basic value
block inline inline-block
No wrap
Must wrap No wrap &
we can set
width/height
inline inline inline
inline inline
inline inline
inllne
long long inline-block
display: inline-
block;
\n
Expecto..
Partronum!!!
\n
\n
\n
\n
display:
inline-
block;
Inline-
block
display: block;
block;
block
black
block
2.3.2 display: inline; - margin
We can not set “margin-top” or “margin-bottom“
on ,
Slide 26
Slide 26 text
2.3.2 display: inline; - padding
And “padding-top”, “padding-bottom”
attributes will override the other elements.
Slide 27
Slide 27 text
Note: inline {text-align: center;}
Slide 28
Slide 28 text
Note: inline {text-align: center;}
“text-align” set alignment for
its child elements (or text)
(child elements should be {display: inline or inline-block)}.
Slide 29
Slide 29 text
2.3.2 display: inline; - border
Slide 30
Slide 30 text
block inline
inline-block
Slide 31
Slide 31 text
2.3.3 display: inline-block;
We can just change the display attribute of
.
Slide 32
Slide 32 text
2.3.3 display: inline-block;
We can set ”display: inline-block;” to horizontally align
those
display: Basic
behavior
margin padding center
block; wrap V V margin: auto;
inline; No wrap No top &
bottom
overlay text-align:
center;
inline-block; No wrap V V text-align:
center;
%JTQMBZ
Tips 1.1: Debug SOP - Trace
Why Cobb is not center?
Scroll ->
Slide 40
Slide 40 text
Tips 1.1: Debug SOP - Trace
Check here
Open developer tool &
click here
Slide 41
Slide 41 text
Tips 1.1: Debug SOP - Trace
Or here
then here!
Slide 42
Slide 42 text
Tips 1.1: Debug SOP - Trace
And find out who commit this bug.
Gotcha!
Slide 43
Slide 43 text
Tips 1.2: Debug SOP - Delete
Or just remove each element until finding the strange
one.
Press
delete(keyboard)
Press
delete(keyboard)
Slide 44
Slide 44 text
Brainstorming: Remove the gap
What happened here?
(gaps)
Because those dinosaurs are too brutal!
Slide 45
Slide 45 text
Note: inline-block __space__ Issue
What happened here?
(gaps)
Hint
Because those dinosaurs are too brutal!
Slide 46
Slide 46 text
Brainstorming: Remove the gap - 2
What happened here?
(gaps)
Because those dinosaurs are too brutal!
Slide 47
Slide 47 text
Note: inline-block __space__ Issue
Equal to
Space! Space everywhere!
So
\n
\n
\n
\t
\t
\t
\t
Slide 48
Slide 48 text
Note: inline-block __space__ Issue
In 2018, we use
“display: flex;”
You may see lots of website use
“float: left;” & “clear: both;” to fix it.
But that’s a little annoying.
Image:
Slide 49
Slide 49 text
Warn: Do not use table layout, No!!!
You may see old website(10 years)
use ,, as web
layout method.
But it is not responsive and it
can not survive in 2018.
Only use in displaying “table” . Image
(mostly)
Slide 50
Slide 50 text
Warn: Repeat, Do not use table layout!
Table layout
Slide 51
Slide 51 text
2. CSS For Layout
Reset: The first step.
width & height: auto & %
Display: Where the magic happens
Position: How to put the element??
Flex & Grid: OMG It’s so useful!!!
or bug!
v
v
v
Slide 52
Slide 52 text
2.4 position
static relative absolute fixed
Default {
left: 20px;
top: 20px;
}
Scroll to
bottom
{
left: 20px;
top: 20px;
}
{
left: 20px;
top: 20px;
}
footer
Always here!
We can not
set left/top
2.4.1 position: relative; (margin & padding)
Margin & Padding
still affect the original space.
Big!!
Slide 56
Slide 56 text
2.4.2 position: absolute;
absolute
{
left: 20px;
top: 20px;
}
Beware the origin!
Not always here!!
Slide 57
Slide 57 text
2.4.2 position: absolute
Slide 58
Slide 58 text
2.4.2 position: absolute; - (origin)
50px
50px
40px
40px
The origin point will
be locate at upper
left corner of its
first parent element
which is absolute or
relative. (e.g.p-rela)
<- The origin of cage is here
Origin is here ->
Slide 59
Slide 59 text
2.4.2 position: absolute - (center)
We can use {left:0; right:0; margin: auto}
to horizontally center the element.
Slide 60
Slide 60 text
2.4.3 position: fixed;
Slide 61
Slide 61 text
2.4.3 position: fixed;
40px 40px
Slide 62
Slide 62 text
2. CSS For Layout
Reset: The first step.
width & height: auto & %
Display: Where the magic happens
Position: How to put the element??
Flex & Grid: OMG It’s so useful!!!
or bug!
v
v
v
v
Slide 63
Slide 63 text
2.5.1 Flexbox Layout
Flexbox Layout
Image-Credit: How Flexbox works — explained with big, colorful, animated gifs
Slide 64
Slide 64 text
2.5.1 Flexbox Layout
Wait, what would happen to
“new” CSS features?
Slide 65
Slide 65 text
Acceptable?
Slide 66
Slide 66 text
Note: CSS - Prefix
-webkit- (Chrome, Safari, newer versions of Opera, almost all iOS browsers (including
Firefox for iOS); basically, any WebKit based browser)
-moz- (Firefox) Ref
Slide 67
Slide 67 text
2.5.1 Flexbox
Slide 68
Slide 68 text
2.5.1 Flexbox
Slide 69
Slide 69 text
2.5.1 Flexbox - flex-wrap
downsizing wrap
Slide 70
Slide 70 text
2.5.1 Flexbox - justify-content
Slide 71
Slide 71 text
2.5.1 Flexbox - align-items
Slide 72
Slide 72 text
2.5.1 Flexbox - align-items
Slide 73
Slide 73 text
2.5.1 Flexbox - center
Center a div vertically &
horizontally
Flexbox
absolute
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
display: flex;
align-items: center;
justify-content: center;
Old but not obsolete
2.5.1 Flexbox - future learning
• Flexbox Cheatsheet
• How Flexbox works — explained with big, colorful,
animated gifs
• A Complete Guide to Flexbox
• Just search ‘flexbox’ on Medium!!
Slide 76
Slide 76 text
2.5.2 Grid (not bootstrap grid)
CSS Grid Layout
Image credit: Responsive Grid Layout: The past, present and future
Slide 77
Slide 77 text
“Well, that’s
embarrassing.”
Slide 78
Slide 78 text
2.5.2 Grid
Image-Credit: CSS grid Intro
Slide 79
Slide 79 text
2.5.2 Grid
與 CSS Grid 的第⼀一次接觸
Learn CSS Grid in 5 Minutes
Or Search CSS grid on Medium!!
Slide 80
Slide 80 text
2. CSS For Layout
Reset: The first step.
width & height: auto & %
Display: Where the magic happens
Position: How to put the element??
Flex & Grid: OMG It’s so useful!!!
or bug!
v
v
v
v
v
Slide 81
Slide 81 text
網⾴頁常⾒見見組成
Image
Slide 82
Slide 82 text
Exercise 1. navbar
你覺得可以怎麼做?
Slide 83
Slide 83 text
Exercise 1. navbar
你覺得可以怎麼切?
Slide 84
Slide 84 text
Exercise 1. navbar
Slide 85
Slide 85 text
Exercise 2. Jumbotron
Photo by Chinda Sam on Unsplash
你覺得可以怎麼做?
Slide 86
Slide 86 text
Exercise 2. Jumbotron
lorem + tab: generate fake long text
Slide 87
Slide 87 text
Exercise 2. background-image resources
Pixbay, stocksnap.io, unsplash…
Just google CC0 images
Slide 88
Slide 88 text
Exercise 2. Image resize & compress tools
We must compress & resize our images.(≤1366px)
Tiny jpg Resizeimage.net
index.html: 10KB
An image: 2MB
Slide 89
Slide 89 text
Exercise 3. cards (3 or 4 columns)
你覺得可以怎麼做?
Slide 90
Slide 90 text
Exercise 3. cards (3 or 4 columns)
Slide 91
Slide 91 text
Exercise 4 Footer
你覺得可以怎麼做?
Slide 92
Slide 92 text
Exercise 4 Footer
Slide 93
Slide 93 text
Exercise 1. navbar - sample answer
Slide 94
Slide 94 text
Exercise 1. navbar - container
70%
> >
Slide 95
Slide 95 text
Example 1. navbar - li > a
>
Slide 96
Slide 96 text
Exercise 2. Jumbotron - sample answer
Photo by Chinda Sam on Unsplash
Slide 97
Slide 97 text
Exercise 2. jumbotron - header
Slide 98
Slide 98 text
Exercise 2. jumbotron - intro
> >
Slide 99
Slide 99 text
Exercise 2. jumbotron - intro > p
>
div.intro
Slide 100
Slide 100 text
Exercise 2. jumbotron - intro > a.btn
>
div.intro
Slide 101
Slide 101 text
Exercise 3. cards sample answer
你覺得可以怎麼做?
Slide 102
Slide 102 text
Exercise 3. cards sample answer
Slide 103
Slide 103 text
Exercise 3. cards sample answer
Slide 104
Slide 104 text
Exercise 4 Footer - sample answer
Slide 105
Slide 105 text
3. RWD & Mobile
Devices: Lots of devices
Attributes: viewport, media, vw/vh
Event: No hover but swipe
Components: Different thinking