Study guide
12.3 Layout Systems: Flexbox, CSS Grid, and Positioning
TExES Technology Applications EC-12 242
Track your progress as you read
Finished sections get a check mark.
1 Exam Overview and Study Plan
Exam Overview, Official Blueprint, and Study Plan
2 Chapter 1: Technology Systems, Hardware, Networking & Troubleshooting
1.1 Hardware Architecture, Storage, and Peripheral Integration 1.2 Network Topologies, Infrastructure, and Protocols 1.3 File Management, Media Compatibility, and Technical Troubleshooting
3 Chapter 2: Information Literacy, Digital Citizenship & Educational Integration
2.1 Information Fluency, Research Strategies, and Source Evaluation 2.2 Digital Citizenship, Legal/Ethical Use, and Cyber Safety 2.3 Technology Problem-Solving, Project Management, and Accessibility 2.4 Instructional Planning, TEKS Integration, and Assessment in Technology
4 Chapter 3: Visual Design Principles, Elements, and Composition
3.1 Elements of Design in Digital Media 3.2 Principles of Design and Visual Composition 3.3 Compositional Rules, Perspective, and Depth 3.4 Rubrics and Graphic Design Critique
5 Chapter 4: Color Theory, Color Models, and Digital Image Types
4.1 Color Theory and Color Harmonies 4.2 Color Models and Output Workflows 4.3 Bitmap and Vector Graphics Architecture 4.4 Graphic and Photo Editing Tools and Workflows
6 Chapter 5: Typography, Page Layout, and Document Design
5.1 Anatomy and Classifications of Typography 5.2 Type Hierarchy, Formatting, and Typographic Metrics 5.3 Page Layout Systems, Grid Structures, and Print Specifications 5.4 Graphic Design Impact, Visual Persuasion, and Career Pathways
7 Chapter 6: 2D and 3D Computer Animation Concepts and Techniques
6.1 The Twelve Principles of Animation in Digital Media 6.2 2D Animation Workflows: Frame-by-Frame, Tweening, and Onion-Skinning 6.3 Fundamentals of 3D Modeling and Geometry 6.4 3D Animation Pipeline: Rigging, Texturing, Lighting, and Rendering
8 Chapter 7: Digital Video Production Stages, Roles, and Techniques
7.1 Preproduction Planning: Scripting, Storyboarding, and Production Logistics 7.2 Production Crew Roles and Responsibilities 7.3 Cinematography, Camera Framing, and Lighting 7.4 Postproduction Editing Workflows and Continuity
9 Chapter 8: Digital Audio Engineering and Production
8.1 Physics of Sound, Microphones, and Audio Capture 8.2 Digital Audio Sampling, Bit Depth, and Audio File Formats 8.3 Audio Postproduction, Mixing, and Sound Design 8.4 Audio/Video Compression Codecs and Container Formats
10 Chapter 9: Multimedia Authoring, Ethics, Copyright, and Distribution
9.1 Multimedia Project Design, Storyboarding, and Brainstorming 9.2 Copyright Law, Fair Use, and Intellectual Property in Multimedia 9.3 Ethical and Societal Impacts of Digital Media Production 9.4 Multimedia Delivery Platforms, Portfolios, and Evaluation
11 Chapter 10: Web Architecture, Server Administration, and Network Protocols
10.1 Internet Infrastructure, DNS, and Top-Level Domains 10.2 Web Protocols and Historical Retrieval Systems 10.3 Web Server Administration, Directory Hierarchies, and Access Control 10.4 Web Server Security, Bandwidth, and Hosting Infrastructure
12 Chapter 11: Web Page Structure, Semantic HTML, and Validation
11.1 HTML5 Document Architecture and Semantic Elements 11.2 Core HTML Elements: Links, Media, Tables, and Forms 11.3 HTML Validation, Text Editors, and Development Tools 11.4 Web Accessibility, Section 508, and WCAG Guidelines
13 Chapter 12: Cascading Style Sheets (CSS) and Responsive Layout Design
12.1 CSS Syntax, Selectors, and the Cascade 12.2 The CSS Box Model and Visual Formatting 12.3 Layout Systems: Flexbox, CSS Grid, and Positioning 12.4 Responsive Web Design, Media Queries, and Cross-Browser Testing
14 Chapter 13: Client/Server Scripting, Interactivity, and Web-Based Gaming
13.1 Client-Side Interactivity with JavaScript 13.2 Server-Side Processing, Dynamic Websites, and Databases 13.3 Web Game Design, Mechanics, and Genre Analysis 13.4 Web Communication, Online Safety, Digital Ethics, and Collaborative Development
12.3 Layout Systems: Flexbox, CSS Grid, and Positioning
Key Takeaways Explain This Topic AI
CSS positioning schemes govern element placement relative to normal flow: relative offsets without disturbing flow space, while absolute and fixed remove elements from flow entirely.
An absolutely positioned element positions itself relative to its nearest positioned ancestor (an ancestor with a position other than static), defaulting to the viewport if none exists.
The z-index property manages stacking order along the z-axis, but only operates on positioned elements or flex/grid children.
Flexbox provides a one-dimensional layout system specialized for aligning and distributing space among items along either a horizontal row or a vertical column.
CSS Grid provides a two-dimensional layout system that orchestrates rows and columns simultaneously using fractional units (fr), explicit tracks, and semantic grid areas.
Last updated: September 2026
12.3 Layout Systems: Flexbox, CSS Grid, and Positioning
Modern web design has evolved far beyond legacy table-based hacks and fragile float clearing routines. Today, CSS delivers a sophisticated suite of layout models capable of solving complex interface challenges. Mastery of contemporary layout requires fluency across three complementary systems: CSS Positioning (for precision coordinate placement and document flow decoupling), Flexible Box Layout / Flexbox (for one-dimensional component alignment), and CSS Grid Layout (for two-dimensional structural scaffolding).
Normal Document Flow and CSS Positioning Schemes
By default, elements render in normal document flow : block elements stack sequentially down the page from top to bottom, while inline elements flow left to right within horizontal line boxes. The position property alters this default behavior, offering five distinct operational modes: Normal Flow -------------------------> position: static (default)
- Offset, Flow Space Preserved --------> position: relative
- Removed from Flow, Ancestor Relative -> position: absolute
- Removed from Flow, Viewport Relative -> position: fixed
- Scroll-Triggered Viewport Pinning ---> position: sticky
- 1. position: static (Default)
The natural baseline for all HTML elements.
Elements are laid out strictly according to the normal flow of the document.
The coordinate offset properties ( top , right , bottom , left ) and the z-index property have zero effect on static elements.
2. position: relative
The element remains within the normal document flow, and its original physical space is strictly preserved on the page. Neighboring elements do not move to fill the void.
Offset properties ( top , bottom , left , right ) shift the visual presentation of the element relative to where it would have naturally rendered.
The Golden Architectural Pattern : The most frequent real-world use of position: relative is not to move the element itself, but to establish a containing block / positioning context for child elements that use position: absolute .
3. position: absolute
The element is completely wiped from the normal document flow . It occupies zero physical space; neighboring elements close together as though the element never existed.
The element is positioned precisely using top , bottom , left , and right relative to its nearest positioned ancestor (any ancestor element with position explicitly set to relative , absolute , fixed , or sticky ).
If no positioned ancestor exists up the DOM tree, the element positions itself relative to the initial containing block (the browser viewport boundary).
4. position: fixed
Completely removed from the normal document flow.
Positioned relative to the browser viewport window itself , maintaining its coordinate position even as the user scrolls through thousands of pixels of page content.
Typical use cases: Persistent top navigation headers, floating "Back to Top" buttons, sticky social share bars, and modal background overlays.
5. position: sticky
A dynamic hybrid between relative and fixed positioning.
An element behaves like position: relative within the normal flow until the user scrolls past a declared threshold (e.g., top: 0px ). At that exact inflection point, it acts like position: fixed , pinning itself to the viewport.
It remains pinned only while scrolling through its immediate parent container; once the parent scrolls completely off screen, the sticky element scrolls away with it.
Stacking Contexts and z-index
When elements overlap, their visual rendering priority along the perpendicular z-axis (depth extending toward the user) is governed by stacking order :
The z-index property accepts integer values (positive, zero, or negative). Higher numbers render in front of lower numbers.
Crucial Rule : z-index only functions on elements that have an explicit position other than static (or direct children of flex and grid containers).
Stacking Context Isolation : An element with z-index: 9999 nested inside a parent with a stacking context of z-index: 1 will still render behind a sibling element with z-index: 2 . Stacking contexts operate hierarchically; a child cannot break out of its parent's stacking plane.
Flexible Box Layout (Flexbox): 1D Component Engine
Flexbox is a one-dimensional layout system engineered to distribute space and align items along a single axis at a time: either as a row (horizontal) or as a column (vertical). MAIN AXIS (flex-direction: row)
- ----------------------------------------------------------->
- +------------------------------------------------------------+
- | +------------+ +------------+ +------------+ |
- CROSS | | Flex Item | | Flex Item | | Flex Item | |
- AXIS | | 1 | | 2 | | 3 | |
- | | +------------+ +------------+ +------------+ |
- v +------------------------------------------------------------+
- The Flex Container and Axis Mechanics
Applying display: flex transforms an element into a flex container, converting its direct children into flex items . Flexbox operates around two perpendicular axes:
Main Axis : The primary direction in which flex items flow, established via flex-direction .
Cross Axis : The axis running perpendicular to the main axis.
Container-Level Properties
flex-direction :
row (Default): Main axis is horizontal, running left-to-right.
row-reverse : Main axis is horizontal, running right-to-left.
column : Main axis is vertical, stacking items from top-to-bottom.
column-reverse : Main axis is vertical, stacking items bottom-to-top.
flex-wrap :
nowrap (Default): Forces all flex items onto a single line, shrinking them if necessary.
wrap : Allows items to wrap onto multiple lines along the cross axis when horizontal space is exhausted.
justify-content (Main Axis Alignment):
flex-start / start : Items packed flush against the start of the main axis.
flex-end / end : Items packed flush against the end of the main axis.
center : Items centered along the main axis.
space-between : First item flush start, last item flush end, equal space distributed between items.
space-around : Equal space on both sides of each item (edges have half the space of interior gaps).
space-evenly : Equal space distributed between every item and outer container boundaries.
align-items (Cross Axis Alignment - Single Line):
stretch (Default): Flex items stretch to fill the container's cross-axis height.
center : Items centered vertically along the cross axis.
flex-start / flex-end : Items aligned to the start or end of the cross axis.
baseline : Items aligned according to the baseline of their internal typography.
gap , row-gap , column-gap : Modern properties specifying gutters between flex items without applying brittle margins.
Flex Item-Level Properties
Flex items dynamically grow or shrink based on available positive or negative free space:
flex-grow : A unitless proportion determining how much excess space an item will absorb (e.g., flex-grow: 1 allows an item to expand and fill available room).
flex-shrink : Dictates the rate at which an item compresses when container space is constrained (default is 1 ). Setting flex-shrink: 0 prevents an item from shrinking below its base size.
flex-basis : The initial size of the item before remaining space is distributed (e.g., 200px , auto ).
Shorthand Recommendation : The flex shorthand ( flex: <grow> <shrink> <basis> ) is often clearer than setting three longhand properties separately, but use whichever form makes the intended sizing behavior easiest to verify.
align-self : Overrides the container's align-items setting for an individual flex item.
CSS Grid Layout: 2D Structural Scaffolding
While Flexbox is optimized for one-dimensional flows, CSS Grid Layout is the first native CSS layout system built expressly for two-dimensional layout —coordinating rows and columns concurrently. Column 1 Column 2 Column 3
- +-----------------+-----------------+-----------------+
- Row 1 | Header | Header | Header | <-- grid-column: 1 / 4
- +-----------------+-----------------+-----------------+
- Row 2 | Sidebar | Main Content | Main Content | <-- Main spans cols 2-4
- +-----------------+-----------------+-----------------+
- Row 3 | Footer | Footer | Footer |
- +-----------------+-----------------+-----------------+
- Grid Architecture Terminology
Grid Container : The parent element declared with display: grid .
Grid Line : The numbered horizontal and vertical dividing lines demarcating columns and rows (indexed starting at 1, from outer left to right, and top to bottom).
Grid Track : The space between two adjacent grid lines—either a column or a row.
Grid Cell : The single unit of intersection between a row track and column track (analogous to a table cell).
Grid Area : Any rectangular space bounded by four grid lines containing one or more cells.
Defining Grid Tracks and the Fractional Unit ( fr )
The fractional unit ( fr ) represents a fraction of the leftover free space in the grid container after fixed tracks are allocated: .dashboard-grid {
- display: grid;
- grid-template-columns: 240px 1fr 2fr;
- grid-template-rows: auto 1fr auto;
- gap: 1.5rem;
- }
In this example, Column 1 is locked at 240px for a sidebar. The remaining container width is divided into three equal fractions ( 1 fr + 2 fr = 3 fr 1\text{fr} + 2\text{fr} = 3\text{fr} 1 fr + 2 fr = 3 fr ); Column 2 receives one share, and Column 3 receives two shares.
Powerful Grid Functions
repeat() Function : Simplifies repetitive track patterns (e.g., repeat(12, 1fr) defines a classic 12-column grid).
minmax() Function : Enforces minimum and maximum boundaries on a track (e.g., minmax(200px, 1fr) ensures a column never shrinks below 200px but can expand freely).
Fluid Grids Without Media Queries : Combining auto-fit or auto-fill with minmax() produces fully responsive grids that wrap automatically as the screen contracts: .card-grid {
- display: grid;
- grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
- gap: 1rem;
- }
- Named Grid Areas ( grid-template-areas )
CSS Grid allows developers to draw visual maps of layout structures using semantic ASCII-art strings: .page-layout {
display: grid;
grid-template-areas:
- "header header"
- "sidebar content"
- "footer footer";
- grid-template-columns: 250px 1fr;
- }
- .site-header { grid-area: header; }
- .site-sidebar { grid-area: sidebar; }
- .site-content { grid-area: content; }
- .site-footer { grid-area: footer; }
- Flexbox vs. CSS Grid Architectural Decision Matrix
Architectural Requirement Optimal Engine Rationale
Whole-page layout scaffolding (Header, Sidebar, Main, Footer) CSS Grid Grid excels at two-dimensional coordinate mapping and structural row/column alignment.
Navigation bars and toolbars Flexbox Flexbox distributes items along a single horizontal axis with dynamic space distribution.
Card component internal alignment (Avatar, title, button pinned to bottom) Flexbox Flexbox column direction allows margin-top: auto to pin call-to-action buttons to the card bottom.
Image and photo galleries CSS Grid Grid enforces rigid, multi-row, multi-column geometric cells with uniform gaps.
Form input with adjacent button Flexbox Allows the input to grow dynamically ( flex: 1 ) while the button retains fixed intrinsic width.
Complex overlapping UI elements CSS Grid Grid permits multiple elements to occupy identical cell coordinates, controlled via z-index .
Flexbox vs. CSS Grid Comparison and Positioning Guide
- Layout Mechanism Dimensionality Primary Focus Flow Behavior Key Defining Properties
- Static Positioning None Default document order Normal flow position: static
Relative Positioning 1D / Coordinate Local visual offset & coordinate origin Normal flow space preserved position: relative , top , left
Absolute Positioning 2D Coordinate Precision placement relative to ancestor Removed from normal flow position: absolute , top , right , bottom , left
Fixed Positioning 2D Coordinate Pinned placement relative to viewport Removed from normal flow position: fixed , top , left , z-index
Sticky Positioning Hybrid Scroll-dependent pinning within parent Normal flow until scroll threshold position: sticky , top: 0
Flexbox 1-Dimensional Content alignment along single axis Flexible item distribution display: flex , justify-content , align-items
CSS Grid 2-Dimensional Track-based scaffolding across rows/cols Strict two-dimensional placement display: grid , grid-template-columns , gap