Skip to content

Instantly share code, notes, and snippets.

@clhenrick
Created August 4, 2014 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clhenrick/c9b6dda38671b46440f3 to your computer and use it in GitHub Desktop.
Save clhenrick/c9b6dda38671b46440f3 to your computer and use it in GitHub Desktop.
mfa dt bootcamp web class: Floats 3; clearing with a subsequent element or clearfix
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Clearfixing Floats</title>
<style type="text/css">
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.parent {
width: 300px;
margin: 0 auto;
background-color: yellow;
border: 10px solid hsla(0, 0%, 0%, 0.6);
}
.parent p {
padding: 10px;
}
.child {
width: 100px;
height: 200px;
padding: 10px;
float: right;
background-color: blue;
}
/* manual clear with an empty element */
.clear {
/*clear: both;*/
}
/* clearfix method */
/* apply the class "group" to the parent
and it will self clear any children */
.group:before,
.group:after {
content: "";
display: table;
}
.group:after {
clear: both;
}
.group {
zoom: 1; /* for IE6 & 7*/
}
</style>
</head>
<body>
<h1>We can <em>clear</em> floats with an empty subsequent element OR <br> by using the <em>clear fix</em> method.</h1>
<h3>Open the web inspector and turn on the clear:both property in the box that has a class of "clear"</h3>
<h3>Then turn it back off add the class "group" to the parent div</h3>
<div class="box parent">
<div class= "box child"></div>
<p> some text and stuff bla bla bla. </p>
<div class="clear">
<!-- this is an empty element for "clearing" the float of the "child" box -->
</div>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment