Banner Image
Banner Image
Banner Image

CSS Clearfix Hack

Clearfix is one type of hack method to force the container’s(which has floating element inside) height based on the floated element. This is also know as Easy Clearing Hack. You can use this below code to avoid that layout issue arise by that floated element on all browsers.

[css]
.clearfix:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}

.clearfix {
display: inline-block;
}

html[xmlns] .clearfix {
display: block;
}

* html .clearfix {
height: 1%;
}
[/css]

Above CSS code containing the content: “.”; property. I have found that the period (or dot) specified in quotes has a nasty tendency to break certain layouts. By adding a literal dot after the .clearfix division (i.e., via the .clearfix:after selector), the clearfix hack creates a stumbling block for certain browsers. And not just for Internet Explorer — depending on the layout, even Firefox will choke a layout upon tripping on an :after-based pseudo-dot. The solution to this subtle design chaos? Replace the literal dot with a single blank space: “content: ” “; — this trick has proven successful so consistently that I now use it as the default property in every clearfix hack that I use.

Blog

In today’s digital world, just having a website is not enough. You need people to…
Learn how to track website performance with the upgraded Search Console Insights — a must-have…
Discover Free & Budget-Friendly WordPress Themes to Build Stunning Websites Without Overspending Creating a professional…
In today’s ultra-competitive eCommerce world, launching a Shopify store is easy. But building a branded,…

Stay Ahead in Digital Innovation

Looking for expert tips, industry insights, and strategies to boost your digital presence? Subscribe to Sharesoft Technology’s weekly LinkedIn newsletter!