Sources
S1 — MDN: Basic concepts of flexbox
URL: https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Flexible_box_layout/Basic_concepts
- authority: official-docs
- supports: Lessons 01-05 — what
display: flexdoes, direct children becoming flex items, theinline-flexvariant, the main axis and cross axis, the full list of initial values a new flex container starts from, Flexbox as a one-dimensional model, start/end lines and writing modes, theflex-flowshorthand,justify-itemsbeing ignored, the predefinedflexshorthand values, and each wrapped line acting as its own flex container. - key-fact: "To create a flex container, set the area's
displayproperty toflex. When we do this, the direct children of that container become flex items." "You can explicitly control whether the container itself is displayed inline or in block formatting context usinginline flexorinline-flexfor inline flex containers orblock flexorflexfor block level flex containers." "The main axis is defined byflex-direction." "The cross axis runs perpendicular to the main axis." "Thejustify-contentproperty is used to align the items on the main axis." "Thealign-itemsproperty aligns all the flex items on the cross axis." "When we describe flexbox as being one-dimensional we are describing the fact that flexbox deals with layout in one dimension at a time — either as a row or as a column. This can be contrasted with the two-dimensional model of CSS Grid Layout." Initial values: "Items display in a row (theflex-directionproperty's default value isrow)." "The items start from the start edge of the main axis." "The items do not stretch on the main dimension but can shrink (a flex-item'sflex-growproperty's default value is0and itsflex-shrinkproperty's default value is1)." "The items will stretch to fill the size of the cross-axis (thealign-itemsproperty's default value isstretch)." "The flex-item'sflex-basisproperty's default value isauto." "All the items will be in a single row (theflex-wrapproperty's default value isnowrap), overflowing their container if their combined width/height exceeds the containing element width/height." "flexbox makes no assumption about the writing mode of the document... If theflex-directionisrowand I am working in English, then the start edge of the main axis will be on the left, the end edge on the right. If I were to work in Arabic, then the start edge of my main axis would be on the right and the end edge on the left. In both cases the start edge of the cross-axis is at the top of the flex container and the end edge at the bottom." "You can combine the two propertiesflex-directionandflex-wrapinto theflex-flowshorthand." "Thejustify-itemsproperty is ignored in flexbox layouts." "Settingflex: initialresets the item to the initial values of the three longhand properties, which is the same asflex: 0 1 auto." "Usingflex: autois the same as usingflex: 1 1 auto." "Usingflex: nonewill create fully inflexible flex items. It is as if you wroteflex: 0 0 auto." "The shorthand you often see in tutorials isflex: 1orflex: 2and so on. This is the same as writingflex: 1 1 0orflex: 2 1 0." "These values forflex-growandflex-shrinkare proportions." "While flexbox is a one dimensional model, it is possible to make flex items wrap across multiple lines. If you do this, you should consider each line as a new flex container. Any space distribution will happen across each line, without reference to the previous or subsequent lines."
S2 — MDN: Aligning items in a flex container
URL: https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Flexible_box_layout/Aligning_items
- authority: official-docs
- supports: Lessons 02, 03, 05 — centering an item on both axes by combining
justify-content: center(main axis) andalign-items: center(cross axis); the value vocabulary both properties share (flex-start/flex-end/center/space-between/space-around/space-evenly),stretchas the initialalign-itemsvalue,baseline,align-selffor a single item, auto margins as the main-axis escape hatch, writing-mode-awarestart/end, andalign-contentfor distributing wrapped flex lines. - key-fact: "To center an element, we use the
align-itemsproperty to align the item on the cross axis... We usejustify-contentto align the item on the main axis, which in this case is the inline axis running horizontally." "The reason the items become the same height is that the initial value ofalign-items, the property that controls alignment on the cross axis, is set tostretch." "Thealign-itemsproperty sets thealign-selfproperty on all of the flex items as a group. This means you can explicitly declare thealign-selfproperty to target a single item. Thealign-selfproperty accepts all of the same values asalign-items, plus a value ofauto, which resets the value to that defined on the flex container." "You can also use the valuespace-betweento take all the spare space after the items have been laid out, and share it out evenly between the items... Withspace-around, items have a half-size space on either end. Or, to cause items to have equal space around them use the valuespace-evenly. Withspace-evenly, items have a full-size space on either end." "When flex items are allowed to wrap across multiple lines, thealign-contentproperty can be used to control the distribution of space between the lines, also known as packing flex lines." "Foralign-contentto have an effect, the cross axis dimension (the height in this case) of the flex container must be greater than needed to display the items." "Remember that with all of these alignment methods, the values ofstartandendare writing mode-aware." "We don't have ajustify-itemsorjustify-selfproperty available to us on the main axis as our items are treated as a group on that axis. However it is possible to do some individual alignment... by using auto margins along with flexbox." "item 4 is separated from the first three items by settingmargin-lefttoauto, which consumes all the space it can in its axis."
S3 — MDN: flex-direction
URL: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/flex-direction
- authority: official-docs
- supports: Lesson 03 —
flex-directionsets the main axis and the direction items flow; its default isrow;columnmakes the main axis vertical; the-reversevalues swap main-start and main-end;row/row-reverseare affected by the container's directionality; and the-reversevalues create a visual-order/DOM-order disconnect that harms assistive-technology users. - key-fact: "The
flex-directionCSS property sets how flex items are placed in the flex container defining the main axis and the direction (normal or reversed)." Initial value:row. "row-reverse: Behaves the same asrowbut the main-start and main-end points are opposite to the content direction." "column-reverse: Behaves the same ascolumnbut the main-start and main-end are opposite to the content direction." "Note that the valuesrowandrow-reverseare affected by the directionality of the flex container. If itsdirattribute isltr,rowrepresents the horizontal axis oriented from the left to the right, androw-reversefrom the right to the left; if thedirattribute isrtl,rowrepresents the axis oriented from the right to the left, androw-reversefrom the left to the right." "Using theflex-directionproperty with values ofrow-reverseorcolumn-reversewill create a disconnect between the visual presentation of content and DOM order. This will adversely affect users experiencing low vision navigating with the aid of assistive technology such as a screen reader."
S4 — MDN: Controlling ratios of flex items along the main axis
- authority: official-docs
- supports: Lesson 04 —
flex-basissets the starting size before free space is distributed;flex-grow/flex-shrinkdivide positive/negative free space by their factors;flex: 1usesflex-basis: 0to make equal items; the definitions of positive and negative free space;min-content/max-contentas the natural sizes anautobasis resolves to; and why shrinking is weighted by flex base size and floored at min-content. - key-fact: "The
flex-basisproperty specifies the initial size of a flex item before any distribution of the positive or negative free space happens." "Theflex-growproperty specifies the flex grow factor, which determines how much a flex item will grow relative to the other flex items... when positive free space is distributed." "To create three equally-sized items... set theflex-basiscomponent to0." "flex-grow: How much of the positive free space does this item get?flex-shrink: How much negative free space can be removed from this item?flex-basis: What is the size of the item before growing and shrinking happens?" "When a flex container has positive free space, it has more space than required to display the flex items inside the container. For example, a500px-wide container, withflex-directionset torowand containing three100px-wide flex items has200pxof positive free space." "A flex container has negative free space when the combined value of the natural sizes of the flex items is larger than the available space in the flex container. If the three flex items in the500px-wide container example above are each200pxwide instead of100px, their combined natural width is600px, resulting in100pxof negative free space." "Generally,min-contentis the smallest size an element can be while still fitting the longest word, andmax-contentis the size the element would need to be to fit all the content without wrapping." "If no such size is set, meaning the item is auto-sized, thenautoresolves to the size of its content... meaning theflex-basisis the item's max-content size." "Theflex-shrinkproperty specifies the flex shrink factor, which determines how much the flex item will shrink relative to the rest of the flex items in the flex container when negative free space is distributed." "The flex shrink factor is multiplied by the flex base size when distributing negative space. This distributes negative space in proportion to how much the item is able to shrink. So, for example, a small item won't shrink to zero before a larger item has been noticeably reduced." "Small items will not shrink to less than their min-content size."
S5 — MDN: Mastering wrapping of flex items
URL: https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Flexible_box_layout/Wrapping_items
- authority: official-docs
- supports: Lesson 05 — default
flex-wrap: nowrapoverflows;flex-wrap: wrapbreaks items onto new lines; thegapproperty spaces flex items and is shorthand forrow-gap/column-gap; each flex line acts as an independent container so a short last line stretches; and the boundary where a component should move to CSS Grid. - key-fact: "The initial value of the
flex-wrapproperty isnowrap. This means if a set of flex items is too wide for their flex container, they will overflow it." "add theflex-wrapproperty with a value ofwrap... Items will then wrap onto new lines when they overflow their container." "use thegapproperty directly on the flex container to create a fixed space between adjacent flex items. Thegapproperty is a shorthand forrow-gapandcolumn-gap." "As the items can grow, they will expand to fill each row completely. If there is only one item on the final line it will stretch to fill the entire line." "There are no flexbox features to tell items in one row to line up with items in the row above — each flex line acts like a new flex container." "If you want layout in two dimensions then you probably want grid layout." "With CSS grid, the last item stays in its grid cell; grid items don't stretch when there are fewer of them in the last row." "when you catch yourself adding widths to flex items in this way or adding empty flex items to take up space, it is a good indication you may want to switch to CSS grid layout for that component." "Thegapproperty is not the only thing that can add space between items. Margins, padding,justify-content, andalign-contentcan also increase the size of the gutter, affecting the actual size of the gap."
S6 — CSS-Tricks: A Complete Guide to Flexbox
URL: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
- authority: authoritative-guide
- supports: Lessons 01, 04, 05 — the main-axis/cross-axis mental model, that only direct children are laid out by the container (so flex containers nest), the recommendation to use the
flexshorthand, and thatgapspaces items only between them, not on outer edges. - key-fact: "The main axis of a flex container is the primary axis along which flex items are laid out" while "the axis perpendicular to the main axis is called the cross axis." "This is the shorthand for flex-grow, flex-shrink and flex-basis combined... It is recommended that you use this shorthand." The
gapproperty "applies that spacing only between items not on the outer edges."
S7 — W3C: CSS Flexible Box Layout Module Level 1
URL: https://www.w3.org/TR/css-flexbox-1/
- authority: official-docs
- supports: Lessons 01-02 — the formal specification definitions of the main axis, the cross axis, and how flex items are placed along the main axis.
- key-fact: "The main axis of a flex container is the primary axis along which flex items are laid out." "The axis perpendicular to the main axis is called the cross axis." "The flex items are placed within the container starting on the main-start side and going toward the main-end side."