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:07] – peter | css:position:absolute_vs_relative_vs_static [2021/08/08 13:04] (current) – peter | ||
---|---|---|---|
Line 9: | Line 9: | ||
< | < | ||
< | < | ||
+ | </ | ||
</ | </ | ||
Line 15: | Line 16: | ||
| | ||
| | ||
- | }.box { | + | } |
+ | .box { | ||
| | ||
| | ||
| | ||
| | ||
- | }#two { | + | } |
+ | #two { | ||
background: green; | background: green; | ||
} | } | ||
Line 26: | Line 29: | ||
{{: | {{: | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== CSS - Position - Relative ===== | ||
+ | |||
+ | <file style.css> | ||
+ | #two { | ||
+ | top: 20px; | ||
+ | bottom: 20px; | ||
+ | background: green; | ||
+ | position: relative; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | {{: | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | * Moves the green box relative to its current position to 20px from the left and top without changing the layout around it. | ||
+ | * Thus, leaving a gap for the green box where it would have been had it not been position | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== CSS - Position - Absolute ===== | ||
+ | |||
+ | <file style.css> | ||
+ | #two { | ||
+ | top: 20px; | ||
+ | bottom: 20px; | ||
+ | background: green; | ||
+ | position: absolute; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | {{: | ||
+ | |||
+ | <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. | ||
+ | </ | ||
+ |
css/position/absolute_vs_relative_vs_static.1628424458.txt.gz · Last modified: 2021/08/08 12:07 by peter