Last active
August 29, 2015 14:04
-
-
Save clhenrick/8d833f5a8cd54f7caddf to your computer and use it in GitHub Desktop.
mfa dt bootcamp web class css positioning example 5: absolute with 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> | |
| <!-- Credit:These positioning examples are credited to Noah Stokes' blog post on A List Apart, CSS positioning 101: http://alistapart.com/article/css-positioning-101 | |
| --> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Example F</title> | |
| <style> | |
| h1, h3, div { | |
| z-index: 10; | |
| text-align: center; | |
| } | |
| .box { | |
| position: absolute; | |
| width: 200px; | |
| height: 200px; | |
| z-index: -9; | |
| } | |
| #box_1 { | |
| background: #ee3e64; | |
| top: 0; | |
| left: 0; | |
| } | |
| #box_2 { | |
| background: #44accf; | |
| top: 0; | |
| right: 0; | |
| } | |
| #box_3 { | |
| background: #b7d84b; | |
| bottom: 0; | |
| left: 0; | |
| } | |
| #box_4 { | |
| background: #ebde52; | |
| bottom: 0; | |
| right: 0; | |
| } | |
| .orange { | |
| background: #f95b34; | |
| position: absolute; | |
| top: 39%; | |
| left: 41%; | |
| width: 40px; | |
| height: 40px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <h1>Four boxes positioned absolutely, <br>each with a box inside them</h1> | |
| <h3>The inner boxes have top: 39% and left: 41% </h3> | |
| <div id="box_1" class="box"> | |
| <div class="orange"></div> | |
| </div> | |
| <div id="box_2" class="box"> | |
| <div class="orange"></div> | |
| </div> | |
| <div id="box_3" class="box"> | |
| <div class="orange"></div> | |
| </div> | |
| <div id="box_4" class="box"> | |
| <div class="orange"></div> | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment