I've been using CSS float property in many works/projects and in many a occasion I've come across clearing the floated element using either and extra html element at the end of the floated element and using clear:both;
in the style for the extra element or by using clearfix
(which is a common work-around for clearing floated element) or sometimes by using overflow:hidden
in the parent's style.
Even though these solutions have worked for me on many occasions depending on the need but I'd really want to know more about these solutions and would appreciate if there are other ways of solving this.
For the sake of better understanding of the question I've created and fiddle and I would appreciate any suggestion or questions.
Fiddle
In the fiddle, I've created 3 examples to explain the solutions I've been using. In example 3, I've used overflow: hidden
but there are problems of using this solution. For instance, if I want some content to overflow its parent, I cannot do in this case.
Some lines of the CSS
I'm using are:
.wrapper {
width: 300px;
}
.sidebar {
float: left;
width: 100px;
height: 300px;
background-color:#f9b25e;
}
.content {
margin-left: 100px;
background-color:#45ca5f;
}
.column-left {
float: left;
width: 100px;
height: 100px;
background-color: #448bcc;
}
.column-right {
float: left;
width: 100px;
height: 200px;
background-color: #dd4444;
}
/* Example 1*/
.clearfix:after{
content: '';
display: block;
clear: both;
height: 0;
visibility: hidden;
}
/* Example 2*/
.clear { clear: both; }
/* Example 3*/
.ex-3 .content{
overflow: hidden;
}