Creating Columns with Inline-Block & Calc()
Master CSS Layout Techniques with Modern Calculations
Core Concepts You'll Master
Inline-Block Display
Learn how to create flexible column layouts using the inline-block display property for responsive design.
CSS Calc Function
Discover how to perform mathematical calculations mixing different units like percentages and pixels.
Advanced CSS Selectors
Master pseudo-selectors like :not and :last-child to target specific elements with precision.
Project Setup Steps
Close All Files
Close all open files in your code editor to avoid confusion during the exercise
Open Project Folder
Navigate to Desktop > Class Files > Advanced HTML CSS Class and open the Tahoe 3 Columns folder
Preview Initial Layout
Open index.html and preview it in your browser to see the starting three-section layout
The 950px breakpoint was chosen through testing and adjustment based on how the content fits, not on any specific device size. This content-first approach ensures optimal readability.
Column Width Distribution
Methods to Fix Inline-Block Spacing
| Feature | Same Line Tags | HTML Comments |
|---|---|---|
| Code Readability | Poor | Good |
| Maintenance | Difficult | Easy |
| Effectiveness | Works | Works |
| Recommended | No | Yes |
With inline-block, elements behave like text and align on the baseline (bottom) by default. Use vertical-align: top to align column tops instead.
section:not(:last-child) means any section that is not the last element within the parent container
CSS Calc Implementation Process
Add Right Margin
Apply 30px right margin to all sections except the last using the :not(:last-child) selector
Calculate Total Margin
Determine total margin space needed: 2 columns × 30px = 60px total margin space
Apply Calc Formula
Use calc((100% - 60px)/3) to subtract fixed pixels from percentage and divide by column count
For addition and subtraction, the + and - operators must always be surrounded by whitespace. For multiplication and division, whitespace is optional but recommended for consistency.
Space Distribution Calculation
Key Takeaways
