css:position:absolute_vs_relative_vs_static
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
css:position:absolute_vs_relative_vs_static [2021/08/08 12:03] – peter | css:position:absolute_vs_relative_vs_static [2021/08/08 13:04] (current) – peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== CSS - Position - Absolute vs Relative vs Static ====== | ====== CSS - Position - Absolute vs Relative vs Static ====== | ||
- | ===== index.html | + | ===== CSS - Position - Static |
- | <code html> | + | <file index.html> |
<div class=”parent”> | <div class=”parent”> | ||
< | < | ||
Line 10: | Line 10: | ||
< | < | ||
</ | </ | ||
- | </code> | + | </file> |
- | ==== style.css ==== | + | < |
- | + | ||
- | < | + | |
.parent { | .parent { | ||
| | ||
| | ||
- | }.box { | + | } |
+ | .box { | ||
| | ||
| | ||
| | ||
| | ||
- | }#two { | + | } |
+ | #two { | ||
background: green; | background: green; | ||
} | } | ||
- | </code> | + | </file> |
- | < | + | |
- | .parent | + | {{:css:position: |
- | | + | |
- | | + | ---- |
- | }.box { | + | |
- | display: inline-block; | + | ===== CSS - Position - Relative ===== |
- | background: red; | + | |
- | width: 100px; | + | <file style.css> |
- | height: 100px; | + | #two { |
- | }#two { | + | top: 20px; |
+ | bottom: 20px; | ||
background: green; | background: green; | ||
+ | position: relative; | ||
} | } | ||
+ | </ | ||
- | <div class=”parent”> | + | {{: |
- | <div class=”box” id=”one”> | + | |
- | <div class=”box” id=”two”> | + | <WRAP info> |
- | <div class=”box” id=”three”> | + | **NOTE: |
- | <div class=”box” id=”four”> | + | |
- | </div> | + | * Moves the green box relative to its current position to 20px from the left and top without changing the layout around it. |
- | </html> | + | * Thus, leaving a gap for the green box where it would have been had it not been position |
+ | |||
+ | </WRAP> | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== CSS - Position - Absolute ===== | ||
+ | |||
+ | <file style.css> | ||
+ | #two { | ||
+ | top: 20px; | ||
+ | bottom: 20px; | ||
+ | background: green; | ||
+ | position: absolute; | ||
+ | } | ||
+ | </file> | ||
+ | |||
+ | {{: | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | * It will not leave any gap where it would have been. | ||
+ | * The position of the Green Box is based on its parent position (the dotted border). | ||
+ | * Thus, moving 20px to the left and bottom from the top-left origin of the dotted border. | ||
+ | </WRAP> | ||
css/position/absolute_vs_relative_vs_static.1628424187.txt.gz · Last modified: 2021/08/08 12:03 by peter