
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
How to clear floats with the "clearfix" hack with CSS?
To clear floats with the clearfix hack using CSS, the code is as follows −
Example
<!DOCTYPE html> <html> <head> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } div { border: 3px solid rgb(21, 0, 114); padding: 5px; } img { float: right; } .clearfix { overflow: auto; } </style> </head> <body> <h1>Clearfix hack example</h1> <h2>Without Clearfix</h2> <div> <img src="https://i.picsum.photos/id/17/300/300.jpg" width="100" height="100"/> Sample Text </div> <h2 style="clear:right">With Clearfix</h2> <div class="clearfix"> <img src="https://i.picsum.photos/id/17/300/300.jpg" width="100" height="100"/> Sample Text </div> </body> </html>
Output
The above code would produce the following output −
- Related Articles
- How to clear an input field on focus with CSS?
- How to clear the EEPROM with Arduino?
- How to clear all cookies with JavaScript?
- How to clear HTML form fields with jQuery?
- How to clear an entire Treeview with Tkinter?
- How to clear the text entered in Selenium with python?
- How to hack WhatsApp? Easy tricks.
- How to Hack an Open WiFi?
- Clearfix Bootstrap class
- How to delay the Transition Effect with CSS
- How to work with CSS Transitions?
- How to fill columns with CSS
- How to style images with CSS?
- How to create tooltips with CSS?
- How to create "notes" with CSS?

Advertisements