Topics Covered in This HTML & CSS Tutorial:
Master two essential techniques for managing CSS float layouts: using overflow hidden to clear floats and implementing the robust clearfix methodology for professional web development.
Exercise Preview

Exercise Overview
In this hands-on exercise, you'll tackle one of web development's classic challenges: managing CSS float behavior and preventing layout collapse. While modern CSS Grid and Flexbox have largely superseded floats for layout, understanding float clearing remains crucial for maintaining legacy codebases and achieving specific text-wrapping effects. You'll learn both the overflow hidden technique and the more robust clearfix methodology—skills that demonstrate your mastery of fundamental CSS concepts.
Exercise Setup Process
Navigate to Project Files
Open the Clearfix folder located in Desktop > Class Files > Advanced HTML CSS Class in your code editor
Open Starting Files
Launch volunteer.html from the Clearfix folder and preview it in your browser to see the initial layout
Identify Layout Goals
Recognize that the form and volunteer opportunities should display as columns on larger screens
Getting Started
- We'll be switching to a new folder of prepared files for this exercise. In your code editor, close all open files to avoid confusion and ensure a clean workspace.
- For this exercise we'll be working with the Clearfix folder located in Desktop > Class Files > Advanced HTML CSS Class. If you're using a modern editor like Visual Studio Code, Sublime Text, or WebStorm, open this entire folder as your project workspace for better file management.
- Open volunteer.html from the Clearfix folder.
Preview volunteer.html in a browser to understand the current layout.
- You'll see a volunteer registration form positioned above a Volunteer Opportunities section.
- This single-column layout works well on mobile and tablet devices, but on larger desktop screens, we can improve usability by creating a two-column layout that maximizes screen real estate.
Creating 2 Columns & Clearing the Float
Now we'll transform this single-column layout into a responsive two-column design, then address the float-related issues that arise.
Let's examine the HTML structure. Return to volunteer.html in your code editor.
- Within the main tag, you'll find a div with class form-column containing the registration form, followed by an aside element with volunteer opportunities.
- This semantic structure is ideal for creating columns—the main content (form) and supplementary content (opportunities) are clearly separated.
- Open main.css from the css folder within the Clearfix directory.
Navigate to the bottom of the file and locate the min-width: 930px media query. Below the existing h2 rule, add these column definitions:
.form-column { width: 60%; float: left; } aside { width: 35%; float: right; }This creates a 60/35 split with 5% natural spacing between columns—a comfortable reading width for both sections.
Save the file and reload the page in your browser.
- You should now see the form on the left and Volunteer Opportunities on the right in a clean two-column layout.
- However, you'll notice the footer text now appears beside the right column instead of below both columns.
- More problematically, the footer's gray top border has jumped up behind the column headers, creating a visual mess.
This behavior demonstrates a fundamental characteristic of floated elements: they're removed from the normal document flow and don't contribute to their parent container's height calculations. The footer has moved up to fill what the browser perceives as empty space. We need to force the footer to clear past both floated columns.
- Return to main.css in your code editor.
In the min-width: 930px media query, below the aside rule, add this clearing rule:
footer { clear: both; }- Save the file and reload the page in your browser.
Scroll down to verify the footer is now positioned below both columns where it belongs.
While the footer placement is correct, there's still an issue: the expected spacing above the footer is missing. The main tag should provide bottom padding, but it's not visible because the main container has collapsed. The clear property moved the footer down but didn't prevent the parent element collapse—a common pitfall when working with floated layouts.
Floated elements don't take up vertical space in the document flow, causing parent containers to collapse and subsequent elements to move up unexpectedly.
Column Width Distribution
Using Overflow Hidden
Let's explore a more elegant approach to clearing floats that addresses the root cause of container collapse.
- Return to main.css in your code editor.
- Delete the footer rule you just added from the min-width: 930px media query—we're going to solve this more effectively.
Locate the main.content-wrapper rule within the min-width: 930px media query and add the overflow property:
main.content-wrapper { padding: 40px 30px; overflow: hidden; }Professional Insight: The overflow property forces an element to acknowledge and accommodate all its content, including floated children. When set to hidden, it creates what's called a "block formatting context," making the container expand to contain its floated children. This is more robust than clearing individual elements because it addresses the structural issue at the container level.
- Save the file and reload the page in your browser.
Scroll down to confirm the footer now sits properly below both columns with appropriate spacing above it.
Using the overflow property forces an element to look at its content and adjust its height even if it only contains floated elementsOverflow Hidden Method
When Overflow Hidden Does Not Work
While overflow hidden is powerful, it has limitations. Let's create a scenario that demonstrates when you need alternative clearing methods.
- Currently, the icons in the aside column sit above their accompanying text. Let's improve the visual hierarchy by floating these icons so text wraps around them naturally. Target the icons using their existing opportunity-icon class.
- Return to main.css in your code editor.
Find the .opportunity-icon rule in the general styles section (outside any media queries) and enhance it:
.opportunity-icon { width: 100px; float: left; margin-right: 20px; }- Save the file and reload the page in your browser.
- In the right column, text now flows naturally around the icons, creating a more integrated design.
- Now resize your browser from wide to narrow, stopping just after the layout reverts to single-column mode.
Scroll down and examine the School Tutor section carefully.

Notice how the icon extends beyond the gray background, breaking the visual consistency. This happens because the floated icon doesn't contribute to the section's height calculation—the container only considers the text height. With no suitable HTML element available for clearing, let's attempt the overflow hidden approach.
- Return to main.css and locate the aside section rule.
Add the overflow property to prevent section collapse:
aside section {Code Omitted To Save Space
position: relative; overflow: hidden; }- Save and reload to test the change.
While this fixes the container collapse and provides proper padding below the icon, we've created a new problem: the Flexible time badge is being clipped because it's positioned outside its container bounds.
This demonstrates the primary limitation of overflow hidden: any content that extends beyond the container boundaries gets cropped. When you have absolutely positioned elements or other content that intentionally breaks container bounds, you need a different solution.
- Remove the
overflow: hidden;property from the aside section rule—we'll implement a better approach.
The Flexible label gets hidden when using overflow: hidden because it extends beyond the section boundaries using absolute positioning.
Using Clearfix
The term clearing floats encompasses various techniques for managing float-related layout issues. While CSS Grid and Flexbox have largely replaced floats for layout in modern web development, understanding float behavior remains essential for legacy code maintenance and specific design requirements.
Float was originally designed for text wrapping around images—think magazine-style layouts where text flows around photographs. However, it became the primary method for creating multi-column layouts before modern CSS layout methods existed. This dual purpose often creates confusion about when and how to clear floats properly.
The clear property ensures that elements appear below floated content rather than beside it, and can resolve container collapse issues. However, clear requires an actual HTML element to work with. When no suitable element exists, or when overflow hidden would crop important content, clearfix provides an elegant solution.
Clearfix is a CSS technique that creates a virtual clearing element using pseudo-selectors, eliminating the need for extra HTML markup while avoiding the content-cropping risks of overflow hidden. This approach has become an industry standard for robust float management.
Locate the footer rule in the general styles section (not within any media query) and add this clearfix implementation below it:
.clearfix::after { content: ""; display: table; clear: both; }How This Works: The ::after pseudo-element creates invisible content after the clearfix element. By setting display: table, we create a block-level element that responds to the clear: both property, forcing it below any floated siblings. The empty content string makes this clearing element invisible to users while still functional for layout purposes.
Save the file. Now we need to apply the clearfix class to the collapsing section containers.
Switch to volunteer.html and add the clearfix class to all three opportunity sections:
<section class="clearfix"> <div class="time-badge">Evening</div>Code Omitted To Save Space
</section> <section class="clearfix"> <div class="time-badge">Day</div>Code Omitted To Save Space
</section> <section class="clearfix"> <div class="time-badge">Flexible</div>Code Omitted To Save Space
</section>- Save both files and reload the page in your browser.
- The Flexible badge should now be fully visible, and all sections should maintain consistent padding. The clearfix has resolved the container collapse without cropping any content.
Test responsiveness by resizing between wide and narrow views—both single-column and two-column layouts should render perfectly.
Overflow Hidden vs Clearfix
| Feature | Overflow Hidden | Clearfix |
|---|---|---|
| Implementation | Single CSS property | CSS rule + HTML class |
| Content Safety | May hide content | Preserves all content |
| HTML Changes | None required | Add class to elements |
| Flexibility | Limited | Highly flexible |
Implementing Clearfix
Create CSS Rule
Add .clearfix::after rule with content, display: table, and clear: both properties
Apply Class
Add clearfix class to HTML elements that contain floated content
Test Results
Verify that parent containers maintain proper height without hiding content
Another Use of Overflow Hidden
Beyond clearing floats, overflow hidden offers another useful layout technique. Let's create a structured two-column effect within each opportunity section.
- Return to main.css in your code editor.
Find the aside section p rule and add the overflow property:
aside section p { font-size: 1rem; margin: 0; overflow: hidden; }- Save the file and reload the page.
The text now maintains consistent width alignment with the first line, creating a clean two-column effect instead of wrapping below the icon.
The Technical Explanation: When text flows around a floated element, different lines have different available widths—shorter lines beside the float, longer lines below it. The overflow hidden property creates a new block formatting context for the paragraph, which respects the float boundary and maintains consistent width throughout the entire text block. This creates the appearance of two distinct columns rather than wrapping text.
Overflow hidden on paragraph elements prevents text from wrapping below floated images, maintaining consistent column widths throughout the text block.
Optional Bonus: Using Border-Radius to Round Images
While we're enhancing this layout, let's explore border-radius for modern visual polish—a technique that's become essential for contemporary web design.
- Return to main.css in your code editor.
In the .opportunity-icon rule, add subtle corner rounding:
.opportunity-icon {Code Omitted To Save Space
margin-right: 20px; border-radius: 8px; }Save and reload to see the softened corners on the opportunity icons.
The subtle rounding creates a more approachable, modern aesthetic. However, circular images often work even better for profile pictures and icons in contemporary design.
- Return to main.css for a more dramatic transformation.
Update the border-radius to create perfect circles:
.opportunity-icon {Code Omitted To Save Space
margin-right: 20px; border-radius: 50%; }Pro Tip: Using 50% border-radius creates perfect circles regardless of the element's dimensions, making it ideal for responsive designs where image sizes might vary.
Save and reload to see the polished circular icons—a design choice that's become standard in modern web applications and gives your layout a professional, contemporary feel.
Border-Radius Techniques
Subtle Rounding
Use small pixel values like 8px for gentle corner rounding that maintains the rectangular shape.
Perfect Circles
Use 50% border-radius to create perfect circular shapes from square images or elements.