Fog of details ahead!
Do not 'learn off'.
Look-up when needed.
Other: floating, positioning, multicolumn text.
In RWD, we adapt the layout to the characteristics of the device/window.
E.g. page layout
one-column layout for narrow devices/windows;
two-column layout when there is more room;
three-column layout when there is even more room.
E.g. component layout
elements are stacked on narrow devices/windows;
they are side-by-side when there is more room.
A flexbox contains items, which are laid out in a one-dimensional way,
either in rows or in columns.
The items in the flexbox can 'flex',
grow or shrink.
Don't use flexbox when flow layout is sufficient!
On the container:
display: flex;
Parent properties (the flexbox itself) (the container) |
Child properties (the flex items) (the contents) |
---|---|
flex-direction |
order |
flex-wrap |
flex-grow |
justify-content |
flex-shrink |
align-items |
flex-basis |
align-content |
align-self |
<section class="parent">
<article class="child">
<p>
Short text.
</p>
</article>
<article class="child">
<p>
This is a much longer text. The reason it is
longer is because it has a lot more words it.
Words like these. And these. Also these.
</p>
</article>
<article class="child">
<p>
This is a medium-length text.
</p>
</article>
</section>
.parent {
width: 80vw;
height: 80vh;
margin: 0 auto;
background-color: lightblue;
}
.child {
padding: 1em;
border: 1px solid black;
background-color: yellow;
}
We see a big blue area with three yellow boxes, layed out using flow layout.
flex: initial
flex: auto
flex: 1
flex: initial
, see how justify-content
distributes spare space in the flex direction, and align-items
distributes spare space in the other direction
.parent {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: flex-start;
}
.child {
flex: initial;
}
article
s in the HTMLflex-wrap: nowrap
to flex-wrap: wrap
.parent {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-start;
align-items: flex-start;
}
.child {
flex: initial;
}
Grid Layout makes two-dimensional layouts easy (easier).
A grid contains items arranged in columns and rows
A grid contains items arranged in columns and rows
article
s, replace the flexbox by gridgrid-template-columns
to, e.g.
1fr 2fr 1fr
repeat(4, 1fr)
3fr repeat(2, 1fr)
repeat(auto-fill, 20em)
gap: 1em;
.parent {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}