build-your-own.org
BOOK
BLOG
SUBSCRIBE
build-your-own.org
prev ◄─┐
Contents
┌─► next
A Visual Guide To CSS
CHAPTER
Book info
Layout concepts
4 layouts: fl
ow, table, fl
exbox, grid
15
Pt2. Layout
Layout concepts
1
2
3
4
1
2
3
Flow
:
The
default
layout.
Deals with mostly
text
, not boxes
.
Limited support for alignments, esp. vertically.
Text surround "
fl
oat
" elements.
Cannot do much layout at all. MSWord on Web.
Table
:
The
fi
rst
useful
layout.
Places contents into a
grid
.
Has both horizontal and vertical alignment.
Superseded by newer layouts. Still used in emails.
Flexbox
:
The
fi
rst
proper
layout.
Deals with
boxes
instead of text.
Flows elements vertically or horizontally.
Has both horizontal and vertical alignment.
Grid
:
The
second
proper
layout.
Like table, but more sophisticated
Has both horizontal and vertical alignment.
Can automatically adjust the number of columns.
older
newer
2 ways to bypass layout
Y
X
Y can be either:
●
an ancestor
●
or the viewport.
2. off
set after the layout is done
1. position X relative to Y
NOTE
: Bypassing layout can cause
overlap
, which is controlled with
z-index
.
Flow layout: text-oriented
16
Pt2. Layout
Layout concepts
text fl
ow horizontally
lines stack vertically
(no way to align content)
Vertical text
switch the direction
with
writing-mode
Flow layout: fl
oats
float: left;
float: right;
Floated elements
stick out
of its
container and
intrude
into other
containers.
The intended use case is to put text
around images. It's often abused to
do page layouts before fl
exbox.
Flow layout: multi-column
Commonly used in (news)papers to fi
ll the
paper space without overly long lines.
Rarely used in the Web because users can
scroll vertically with infi
nite space.
Document vs. Application
control alignments
HEADER
FOOTER
MAIN
S
I
D
E
create divisions
application layout (
table
,
fl
exbox
,
grid
)
Every
fl
ow
feature is for
formatting documents!
Flexbox: create divisions
17
Pt2. Layout
Layout concepts
1
2
hi
3
main axis
cross axis
1
2
3
hello
main axis
cross axis
main axis
: items fl
ow horizontally or vertically
cross axis
: stretch to fi
t the available space
Division-based design with fl
exbox or grid
HEADER
FOOTER
MAIN
S
I
D
E
1
3
2
2
outer fl
exbox
(vertical)
inner fl
exbox
(horizontal)
nested fl
exbox
(result)
HEADER
FOOTER
MAIN
S
I
D
E
single grid
1
History of CSS layouts
fl
ow
table
fl
exbox
grid
1990s
1990s
2015
2017
The WWW is
designed to
share linked
documents
without
much layout
at all.
But even
the simplest
page has a
layout more
complicated
than a
document.
Real layouts
were added
decades
later. This is
what you
should learn
in 2024+!
The dark age of CSS:
Tableless design with
fl
oat-based hacks.
Vertical centering
was a meme.
This is why you think
CSS is hard.
(
Error report | Ask questions
)
@ build-your-own.org
A Visual Guide To CSS
prev ◄─┘
Contents
└─► next