User Tools

Site Tools


css:position:absolute_vs_relative_vs_static

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
css:position:absolute_vs_relative_vs_static [2021/08/08 12:02] petercss: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”>
  <div class=”box” id=”one”>One</div>  <div class=”box” id=”one”>One</div>
Line 10: Line 10:
  <div class=”box” id=”four”>Four</div>  <div class=”box” id=”four”>Four</div>
 </div> </div>
-</code>+</file>
  
-==== style.css ==== +<file style.css>
- +
-<code css>+
 .parent { .parent {
  border: 2px black dotted;  border: 2px black dotted;
  display: inline-block;  display: inline-block;
-}.box {+} 
 +.box {
  display: inline-block;  display: inline-block;
  background: red;  background: red;
  width: 100px;  width: 100px;
  height: 100px;  height: 100px;
-}#two {+} 
 +#two {
   background: green;   background: green;
 } }
-</code+</file
-<html> + 
-<div class=”parent”> +{{:css:position:css_-_position_-_static.png?600|}} 
- <div class=”box” id=”one”>One</div+ 
- <div class=”box” id=”two”>Two</div+---- 
- <div class=”box” id=”three”>Three</div+ 
- <div class=”box” id=”four”>Four</div+===== CSS - Position - Relative ===== 
-</div+ 
-</html>+<file style.css
 +#two 
 +  top: 20px; 
 +  bottom: 20px; 
 +  background: green; 
 +  position: relative; 
 +
 +</file> 
 + 
 +{{:css:position:css_-_position_-_relative.png?600|}} 
 + 
 +<WRAP info> 
 +**NOTE:**  Relative Position places an element relative to its current position. 
 + 
 +  * 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 
 + 
 +</WRAP
 + 
 +---- 
 + 
 +===== CSS - Position - Absolute ===== 
 + 
 +<file style.css> 
 +#two { 
 +  top: 20px; 
 +  bottom: 20px; 
 +  background: green; 
 +  position: absolute; 
 +
 +</file> 
 + 
 +{{:css:position:css_-_position_-_absolute.png?600|}} 
 + 
 +<WRAP info> 
 +**NOTE:**  Absolute Position has the offset relative to the parent. 
 + 
 +  * 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.1628424170.txt.gz · Last modified: 2021/08/08 12:02 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki