bobD bobD - 1 year ago 95
CSS Question

why not setting default position to relative?

I recently realized how useless the

position: static
Is , It doesn't offer you anything unless the
also does.

In fact my question Is "why not just adding this line to our CSS file ?"

* { position:relative; }

so we are always able to easily position any element
ly from It's parent or moving the element It self around just by
left: ...
or the same for any direction.

so why elements are not positioned to
by default?


Answer Source

static positioning is the default because it simply doesn't "interfere" with the positioning of any other element on the page. In that sense, it is the least disruptive state an element can have. Also, when we are talking about the rendering of the web page which is a very costly and sophisticated operation - it's faster to just draw a page with a lot of static elements than otherwise positioned elements. Modern browsers definitely are very advanced in that regard, but it certainly played a role for browsers 20 years ago.

In terms of convenience: Imagine an element on a dynamic page which you want to position absolutely. You know, which element you want to position it to, but you don't know how many levels might be in between. With static positioning, you just declare position:relative on your anchor element. With all elements having relative positioning you somehow would need to reposition all elements in between, giving you a hard time.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download