Creating Columns: Intro to CSS Grid & Media Queries
Master responsive layouts with CSS Grid and media queries
Core Technologies You'll Master
CSS Grid
Create flexible column layouts using fractional units and grid properties. Learn to define grid containers and control item positioning.
Media Queries
Apply conditional CSS based on screen size. Implement responsive breakpoints that adapt your layout across devices.
Mobile-First Design
Start with mobile layouts and enhance for larger screens. Configure viewport settings for proper mobile rendering.
Project Setup Process
Open Project Files
Navigate to Desktop > Class Files > Web Dev Class > Resume folder and open resume.html in your code editor
Preview in Chrome
Open resume.html in Chrome browser to see the current layout and prepare for DevTools usage
Examine HTML Structure
Review the wrapper div, main element with 3 sections, and identify target elements for grid layout
The fr unit represents a fraction of the leftover space in the grid container
Grid Column Distribution
| Feature | Left Column | Right Column |
|---|---|---|
| Grid Value | 2fr | 1fr |
| Space Allocation | 2/3 of available width | 1/3 of available width |
| Content Purpose | Work Experience | Education |
Open DevTools with Cmd-Opt-I (Mac) or Ctrl-Shift-I (Windows) and resize the window while watching the pixel dimensions in the top-right corner. Look for the point where the 2-column layout becomes cramped.
Common Breakpoint Ranges
Resize back and forth across the 700px threshold to see the responsive behavior in action.
When two rules have the same specificity, the latter rule wins. This is why media queries are placed below general styles - they override the base styles when conditions are met.
Implement mobile-first grid behavior by modifying the main rule to use a single column by default:
main {
display: grid;
grid-template-columns: 1fr;
gap: 30px;
}
This creates a single column that utilizes all available space—perfect for mobile reading patterns where users scroll vertically through content.
You'll notice the layout still tries to create two columns because our #statement rule is still forcing a span of 2 columns. We need to move this desktop-specific rule into our media query.
Paste it inside the media query:
@media (min-width: 700px) {
body {
margin: 20px;
}
#statement {
grid-column: span 2;
}
}
Now the statement will only span two columns on larger screens where we actually have two columns.
Perfect! Now you have a clean single-column mobile layout. Let's add the 2-column behavior for larger screens.
Add a main rule inside your media query:
@media (min-width: 700px) {
body {
margin: 20px;
}
main {
grid-template-columns: 2fr 1fr;
}
#statement {
grid-column: span 2;
}
}
This overrides our mobile single-column layout with the 2-column desktop layout when the screen is wide enough.
Test your responsive design by resizing the browser window. You should see a smooth transition between the single-column mobile layout and the 2-column desktop layout at the 700px breakpoint. This is professional-grade responsive behavior!
Mobile-First vs Desktop-First Approach
| Feature | Mobile-First | Desktop-First |
|---|---|---|
| Base CSS | Mobile layout | Desktop layout |
| Media Query | min-width for larger screens | max-width for smaller screens |
| Performance | Faster mobile loading | More mobile overhead |
| Maintenance | Easier to enhance up | Harder to strip down |
Viewport Meta Tag Impact
The viewport meta tag is essential for responsive design. Without it, mobile browsers assume your site was designed for desktop and scale it down, breaking your responsive layout.
Key Takeaways


