Tuesday 8 December 2015

CSS positioning: Static, Absolute, Relative and Fixed

Static If you don't specify an element's positioning type, it defaults to static. This just means "where the element would normally go." If you don't tell an element how to position itself, it just plunks itself down in the document.

Absolute If the parent not go static, then the absolute position div is according to left.
The first type of positioning is absolute positioning. When an element is set to position: absolute, it's then positioned in relation to the first parent element it has that doesn't have position: static. If there's no such element, the element with position: absolute gets positioned relative to <html>.

To show you how this works, we've set the #outer div to have absolute positioning. This means that when you position the #inner div, it will be relative to #outer. (If #outer had the default positioning of static, then #inner would get positioned relative to the entire HTML document.)

Relative positioning is more straightforward: it tells the element to move relative to where it would have landed if it just had the default static positioning.

Finally, fixed positioning anchors an element to the browser window—you can think of it as gluing the element to the screen. If you scroll up and down, the fixed element stays put even as other elements scroll past.

Static positioning tergantung normally flow.
Absolute positioning tergantung parent.
Relative tergantung static positioning.
Fixed positioning tergantung posisi awal, scroll ke bawah tetap sama.

No comments:

Post a Comment