Floats & Images: Free HTML & CSS Tutorial
Master CSS floats and responsive image techniques
Core CSS Layout Concepts
CSS Float Property
Controls how elements wrap around other elements, essential for text-image layouts. Works by removing elements from normal document flow.
Class Selectors
Target specific elements with reusable styles using the dot notation. More flexible than tag selectors for selective styling.
Responsive Images
Images that scale appropriately across different screen sizes using CSS properties like max-width for fluid layouts.
Tutorial Prerequisites
Build upon previous HTML structure and basic CSS knowledge
Working file from previous exercises or starter template
Hero image and logo files in images folder
For writing code and testing results in real-time
Implementing Responsive Hero Images
Add Image Element
Insert img tag inside main element above h1 with proper src and alt attributes for accessibility
Apply Responsive CSS
Add max-width: 100% rule to img selector ensuring images scale down but never exceed container width
Remove Fixed Dimensions
Remove width and height attributes from img tags to allow CSS-controlled responsive scaling
Hero images should provide visual context for page content and be prominently placed at the top. The max-width: 100% property ensures they remain responsive without breaking layout on smaller screens.
Image Placement Strategy
Alcatraz Logo Addition
Insert first image in paragraph about Alcatraz Island experience
Fisherman's Wharf Logo
Add second image to paragraph describing Fisherman's Wharf attractions
Blazing Saddles Logo
Include third image in outdoor activity paragraph for visual balance
Tag Selectors vs Class Selectors
| Feature | Tag Selectors | Class Selectors |
|---|---|---|
| Targeting | All elements of same type | Specific selected elements |
| Flexibility | Limited control | Precise control |
| Reusability | One style per tag type | Reusable across elements |
| Syntax | img { } | .img-left { } |
Float Implementation Patterns
Left Float Pattern
float: left positions element to left side of container. Text flows around right side creating natural reading flow.
Right Float Pattern
float: right positions element to right side. Creates visual variety and prevents monotonous left-aligned layouts.
Margin Considerations for Floated Images
Apply margin-right to left-floated images and margin-left to right-floated images. This creates space between the image and the text that wraps around it, while avoiding unnecessary spacing on the opposite side.
Key Takeaways
