Last active
December 28, 2015 20:49
-
-
Save mikeplate/7560046 to your computer and use it in GitHub Desktop.
Autoclear a container's floating children
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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