Use Flexbox for layouts primarily arranged along one axis and Grid for row-and-column layouts. Choose float when text genuinely needs to wrap around content.
Practice Exercise
Create an article with a floated image and wrapping text. Then create a three-column gallery with Grid and a toolbar with Flexbox. Compare the layout behaviors.
Quiz — 10 MCQs
- What is normal flow? (A) Default document layout behavior (B) A database query (C) An animation (D) A color format. Answer: A. Normal flow governs ordinary document layout.
- What was float originally designed to support? (A) Text wrapping around an element (B) Creating database tables (C) Changing font weight (D) Loading scripts. Answer: A. Float lets inline content wrap around floated boxes.
- What does clear: both do? (A) Clears relevant floats on both sides (B) Deletes all elements (C) Removes every border (D) Clears browser cache. Answer: A. It prevents the element from sitting beside relevant floats.
- Which property creates a block formatting context conveniently? (A) display: flow-root (B) color: flow-root (C) font-flow: root (D) position: flow. Answer: A. Flow-root establishes a block formatting context.
- Which layout system is suited to a row of toolbar controls? (A) Flexbox (B) Float only (C) Clearfix only (D) Text decoration. Answer: A. Flexbox is designed for flexible one-dimensional layouts.
- Which layout system is suited to a two-dimensional gallery? (A) Grid (B) Outline (C) Float only (D) Font face. Answer: A. Grid manages rows and columns together.
- Do floated elements behave exactly like ordinary in-flow block elements? (A) Yes (B) No (C) Only in Grid (D) Only on mobile. Answer: B. Floats have special positioning and text-wrapping behavior.
- What is clearfix used for? (A) Containing floated children (B) Styling text selection (C) Loading fonts (D) Setting colors. Answer: A. Clearfix historically helped parent containers account for floats.
- Is float the usual first choice for modern page-column layouts? (A) Yes (B) No (C) Only with JavaScript (D) Only for forms. Answer: B. Grid and Flexbox are generally more suitable for layout.
- What does display: inline-block support? (A) Inline participation with box dimensions (B) Fixed positioning only (C) Automatic grid placement (D) Database indexing. Answer: A. Inline-block elements participate inline and support dimensions.
Key Takeaways
- Understand normal flow before learning advanced layouts.
- Use float for text wrapping, not as the default page-layout system.
- Use Flexbox and Grid for most modern interface layouts.