Articles
Practical, deeply explained engineering writing — free to read, no sign-up required.
All Articles
Build a Complete Responsive Web Page Using CSS Flexbox
Build a complete flexbox page in layers. Start with the viewport meta tag. Make the body a column flex container with min-height: 100vh, and give the main element flex: 1, so the footer stays at the bottom. Make the header a wrapping row with justify-content: space-between. Make every section, such as the hero and the feature cards, a wrapping flex row with a flex-basis and a gap.
Build a Professional Dashboard with Sidebar and Main Content
Build a flexbox dashboard from the outside in. Make the page shell a flex container with min-height: 100vh. Give the sidebar a fixed size that cannot shrink, such as flex: 0 0 240px, and let the main area take the rest with flex: 1 and min-width: 0.
Build a Responsive Card and Product Listing Layout
Build a flexbox card layout in three layers. First, make the list a flex container with flex-wrap: wrap and gap, so the cards move to a new line when they do not fit. Second, size each card with the flex shorthand, for example flex: 1 1 180px for a flexible grid, or flex: 0 0 calc((100% - 20px) / 2) when you need exact columns.
Build a Responsive Navigation Bar Using CSS Flexbox
Build a flexbox navigation bar in a fixed order. Write a semantic <nav> with a logo and a list of links. Make the nav a flex container with justify-content: space-between and align-items: center
Flexbox Debugging, Browser Developer Tools and Best Practices
Debug a flexbox layout in a fixed order. Confirm that the container really is a flex container, then that the items are its direct children, then check the free space and the sizes (flex-basis, flex-grow, flex-shrink, minimum and maximum sizes).
Flexbox Overflow, Wrapping and Common Layout Problems
A flex container keeps all its items on one line by default (flex-wrap: nowrap). When the items are too wide, they shrink first, down to their minimum size. If they still do not fit, they overflow the container.
Building Responsive Layouts Using Flexbox and Media Queries
Build the layout for small screens first, usually as a column. Then use a media query such as @media (min-width: 600px) to change the flex container to a row when there is room. Add <meta name="viewport" content="width=device-width, initial-scale=1"> to the page so phones report their real width.
Nested Flex Containers and Complex Layout Structures
A nested flex container is a flex item that also has display: flex, so it lays out its own children while still behaving as an item inside its parent. Every flex container has its own main axis and its own properties, such as flex-direction, justify-content, align-items, gap and flex-wrap.
Understanding Flexbox Sizing, Min-Width and Max-Width
A flex item starts from a base size (its flex-basis, or its width when the basis is auto). The container then shares the free space by growing or shrinking the items, and min-width and max-width have the final say as a floor and a ceiling.
Gap, Auto Margins and Spacing in CSS Flexbox
Use gap on a flex container to put equal space between items, and between lines when the items wrap. Gap never adds space at the outer edges. Use an auto margin on an item, such as margin-left: auto, to make that item absorb the free space and push itself or its neighbours away. In short, gap handles regular spacing, and auto margins handle the exceptions.
Flex Basis and Flex Shorthand – Understanding Item Sizing
flex-basis sets the starting size of a flex item along the main axis, before free space is shared or removed. The flex shorthand sets flex-grow, flex-shrink and flex-basis in one line, for example flex: 1 1 220px. A single number such as flex: 1 means grow 1, shrink 1 and a basis of 0%.
Flex Shrink – Controlling How Items Compress
The flex-shrink property controls how much a flex item shrinks when the items are too large to fit in the container. The default value is 1, so items shrink. Set flex-shrink: 0 to stop an item from shrinking, or a larger number to make it shrink more than the others.