DOM Positioning

A lifelong learner. Love to travel. Listen to music.
Search for a command to run...

A lifelong learner. Love to travel. Listen to music.
No comments yet. Be the first to comment.
Overview When an element in the browser has a conflict of styles, the browser uses a set of rules to determine which style should be rendered. This set of rules is defined as CSS Selector Specificity. For instance, for an element, if we have the foll...
Best Practices for Path Structure, Versioning, and Error Handling

Understanding the Performance Implications of async and defer Attributes

Overview When an element in the browser has a conflict of styles, the browser uses a set of rules to determine which style should be rendered. This set of rules is defined as CSS Selector Specificity. For instance, for an element, if we have the foll...

Master block, inline, flex, and grid to build better web layouts

static: Default position. It does not allow setting properties like top, bottom, left, right, z-index
relative: Acts the same as static. but allows positioning it relatively by putting properties like top, bottom, left, right, z-index
absolute: Remove the DOM from the DOM tree and position it to the root element unless the parent has some position other than static. Ideal way to implemet is, make the current postion absolute and parent element position as relative.
fixed: Move to the top, ignores all the parents, stays there even if it is scrolling
sticky: With sticky position while the parent is relative, the DOM fixed it to the top while scrolling. It is a combination of fixed and relative position. To implement this, the current element should have sticky position and the parent should have relative position.

static vs relativeBoth align with regular DOM flow; however, unlike static, in relative We can set the top, bottom, left, right and z-index.
absolute vs fixedBoth ignore the Dom and move to the very top. However, unlike absoluteThe fixed does not scroll.
absolute and relativeabsolute took the Dom to the very top, unlike there is a parent other than static, like relative.
absolute vs translateabsoulte remove the dom and as a reference use the parent element (other than the static). However, translate also moves the element but uses itself as a reference. Since, translate does not invoke the browser to repaint the DOM, it is more efficient.