Skip to content

Instantly share code, notes, and snippets.

@sanjay1909
Last active August 29, 2015 14:21
Show Gist options
  • Save sanjay1909/61a7fd82289a1a7d6f9a to your computer and use it in GitHub Desktop.
Save sanjay1909/61a7fd82289a1a7d6f9a to your computer and use it in GitHub Desktop.
Code snippet to explain how css float property works
<style>
.container {
height: 30px;
width: 340px;
padding: 2px 2px;
font-size: 12px;
}
.float {
float: left;
}
.after-float {
clear: left;
}
.border {
border-style: solid;
border-width: 8px;
margin: 2px 2px 2px 2px;
}
.color-red {
border-color: red;
}
.color-yellow {
border-color: yellow;
}
.color-green {
border-color: greenyellow;
}
</style>
<div class="container float border color-red">
<p class="border" style=" border-width: 1px;">Left Float</p>
</div>
<div class="container float border color-yellow">
<p class="border" style=" border-width: 1px;">Default: Next Left Float will be relative to previous Left Float</p>
</div>
<div class="container after-float border color-green">
<p class="border" style=" border-width: 1px;">Float Cleared</p>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment