Posted By: dtigraphics | Date Posted: Sunday, Apr 11th 2010
I’m surprised that this “modern” framework is still relying on a 4+ year old method that adds structural markup to solve the float problem. There are many “breakthrough” methods out there and while the below solution (originally written by Andy Clarke). Although IE7 forced everyone to freak a bit a solution was added the original IMHO, superior solution. Again, this works in every situation I’ve ever used. As an aside I’ve been using the below code (changed .clearfix to .cf for brevity) since the original article was written. Possible changes would be moving the * html hack to the IE stylesheet…
Unlike the solution that uses overflow: auto; height: auto; the above works is ALL situations. I use positioning whenever I can to get around IE float bugs. However, when I need to float a few elements I will always use this method; has worked with every site I’ve ever coded and I never need to worry about future changes to my CSS…essentially future-proofing the site.
/* This needs to be first because FF3 is now supporting this */
.cf {display: inline-block;}
.cf:after {
content: " ";
display: block;
height: 0;
clear: both;
font-size: 0;
visibility: hidden;
}
* html .cf {height: 1%;}
.cf {display: block;}
By agrublev
Sunday, Apr 11th 2010I have seen that approach before, i will definitely read into it. I hope you can see that adding 4 different CSS specifications to accomplish the exact same thing the current method has done flawlessly 100% for me in over 200-300 websites might not be optimal.
But as a person who loves to use the best and newest i will research on the manner and do some testing on my own
I’ll even write an article one this.
Thanks
By dtigraphics
Monday, Apr 12th 2010Agreed. If you must use markup to clear floats why not use something more meaningful; <hr class=“clear” > would be fine?
Also, the newest method is to use overflow: auto; and height: auto; (parent container height) but this solution is a bit more problematic…
By agrublev
Monday, Apr 12th 2010Yeah i want to play with the overflow:auto and height: auto;. There also is a default clear using html’s br element. <br clear=“all”
Anyways as i said i would love to do some testing of my own when i get a second to see if there really could be ANY difference in the methods.