Bootstrap: Controlling Grids & Layout
Master responsive design with Bootstrap grid systems
Bootstrap Grid Fundamentals
Responsive Breakpoints
Bootstrap provides xs, sm, md, and lg breakpoints that automatically adjust layout based on screen size. Each breakpoint defines specific pixel ranges for optimal viewing.
12-Column System
Bootstrap uses a 12-column grid where column widths are defined by classes like col-sm-3 or col-lg-6. Columns must add up to 12 per row.
Mobile-First Approach
Start designing for the smallest screens first, then enhance for larger devices. This ensures optimal performance and user experience across all devices.
Open your code editor and load the Bootstrap folder (most modern editors like VS Code, Sublime Text, or Atom support folder-based project management for better file organization).
Preview index.html in your browser and observe the current layout issues. Notice how the navbar sits flush against the browser window edge—a common design problem that creates visual tension and reduces readability. We'll address this spacing issue while also improving the overall page proportions.
In your code editor, open main.css from the css folder to begin implementing our layout improvements.
Add breathing room to your design by inserting the following CSS rule above the existing img rule:
body {
margin: 15px 0;
}
This simple addition creates essential whitespace that professional designers rely on to improve visual hierarchy and user experience.
Save main.css and refresh your browser to see the immediate improvement.
The navbar now has proper spacing, creating a more polished, professional appearance.
Expand your browser to its maximum width (1200px or larger). Even at this generous screen real estate, the four upcoming shows columns feel cramped and underutilized.
Gradually narrow your browser window and watch how the layout responds at Bootstrap's breakpoints. At medium screen sizes, the four-column layout becomes problematic—the content appears squeezed and difficult to scan. The solution is implementing a responsive grid strategy that prioritizes readability at each breakpoint. Keep your browser at this problematic width so you can immediately see the improvements we'll make.
Setup Process for New Students
Clean Workspace
Close any open files and navigate to Class Files > yourname-Mobile and Responsive Class. Delete any existing Bootstrap folder.
Get Starting Files
Select the Bootstrap More Elements & Nesting Grids Done folder and rename it to Bootstrap for consistency.
Initialize Project
Open the Bootstrap folder in your code editor and preview index.html in a browser to verify the starting point.
Bootstrap Breakpoint Behavior
| Feature | Screen Size | Column Class | Layout Result |
|---|---|---|---|
| Extra Small (under 768px) | xs (default) | 100% width stacked | |
| Small (768px+) | col-sm-6 | 2 columns per row | |
| Large (1200px+) | col-lg-3 | 4 columns per row |
Column Width Distribution
Bootstrap Visibility Classes
hidden-xs
Hides elements on extra small screens (under 768px). Perfect for slideshow images that would be too small on mobile devices.
visible-xs
Shows elements only on extra small screens. Useful for mobile-specific content like divider lines between stacked elements.
Hide slideshow images on mobile devices where they would be too small to be effective. Use visible-xs class to add mobile-specific separators between content sections.
The image is 330px. Bootstrap's img-thumbnail style adds 4px of padding and 1px of border on the left and right sides. Bootstrap's column style adds 15px of padding on both sides as well. So here's the math: 15 + 1 + 4 + 330 + 4 + 1 + 15 = 370
Custom Media Query Implementation
Calculate Breakpoint
Determine exact pixel width needed by adding image width plus Bootstrap's padding and borders (330px + 40px = 370px total).
Create Media Query
Use @media (min-width: 371px) and (max-width: 767px) to target the gap between mobile and Bootstrap's sm breakpoint.
Apply Custom Styles
Float images right at 40% width with proper margins to optimize space usage in the intermediate screen size range.
Layout Refinement Checklist
margin: 15px 0 prevents navbar from touching browser edges
Float images right at intermediate sizes for better space utilization
Use clear: both on hr.visible-xs to prevent layout conflicts
Use custom class with media query to add margin-bottom: 30px
Key Takeaways
