Skip to content

Instantly share code, notes, and snippets.

@mikeplate
Last active December 28, 2015 20:49
Show Gist options
  • Select an option

  • Save mikeplate/7560046 to your computer and use it in GitHub Desktop.

Select an option

Save mikeplate/7560046 to your computer and use it in GitHub Desktop.
Autoclear a container's floating children
<!DOCTYPE HTML>
<html>
<head>
<title>Clearing My Floats</title>
<style>
body {
font-family: Calibri, sans-serif;
font-size: 14pt;
width: 990px;
margin: 0px auto;
background-color: #333;
}
h1, h2 {
color: #993;
margin: 10px 0px;
}
.container {
background-color: #fff;
}
.container:after {
content: ' ';
display: table;
clear: both;
}
.container>div {
float: left;
background-color: #eee;
width: 290px;
padding: 10px;
margin: 10px;
}
/* Force container to have height of floating child */
.container-ex1 {
overflow: hidden;
}
/* If you need to show the overflow */
.container-ex2 {
clear: both;
content: "";
display: block;
}
</style>
</head>
<body>
<h1>Headline before</h1>
<div class="container">
<div>Aaaaaa</div>
<div>Bbbbbb</div>
<div>Cccccc</div>
<div>Dddddd</div>
<div>Eeeeee</div>
<div>Ffffff</div>
<div>Aaaaaa</div>
<div>Bbbbbb</div>
<div>Cccccc</div>
<div>Dddddd</div>
<div>Eeeeee</div>
<div>Ffffff</div>
<div>Aaaaaa</div>
<div>Bbbbbb</div>
<div>Cccccc</div>
<div>Dddddd</div>
<div>Eeeeee</div>
<div>Ffffff</div>
</div>
<h2>Footer after</h2>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment