Skip to content

Instantly share code, notes, and snippets.

@junaidtk
Created September 30, 2019 10:43
Show Gist options
  • Save junaidtk/a7080b75761decf4f150397bd977ec8d to your computer and use it in GitHub Desktop.
Save junaidtk/a7080b75761decf4f150397bd977ec8d to your computer and use it in GitHub Desktop.
Give parent div 100% height for floated inner elements
When we apply the float to inner elements and the outer div is not taking the height. Then you can use below snippets.
<div class="containing-div">
<div class="floating-div">
<ul>
<li>List Item One</li>
<li>List Item Two</li>
<li>List Item Three</li>
<li>List Item Four</li>
</ul>
</div>
<div class="floating-div">
<ul>
<li>List Item Five</li>
<li>List Item Six</li>
<li>List Item Seven</li>
<li>List Item Eight</li>
</ul>
</div>
</div>
1)Provide overflow : auto to outer div to make outer height 100%.
.containing-div {
overflow: auto;
}
2)Provide float to outer div.
.containing-div {
float: left;
width: 100%;
}
3)Add a clearing div belown the floated element.
<div class="clear"></div>
4)Add clearing div to parent div.
.clearfix:after {
clear: both;
content: "";
display: table;
}
.clearfix {
clear: both;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment