Search code examples
csspositioncss-float

CSS relative + right (or bottom) almost NEVER work


I've been writing CSS for quite some time now.

I've noticed that

<div style="position: relative; right: 20%; bottom: 20%;">some text</div> 

never works!

relative positioning would work with left and top specified but not with right/bottom. Why?

A quick fix around this is to use "absolute" instead and specify right/bottom in pixels, but I need a reason.

Also, correct me if I'm wrong. Irrespective of whether the external container is positioned absolutely or relatively, does it not make much sense to position something "relative" to the boundaries of that container or should elements inside a container always be positioned "absolute"?

Thank you.


Solution

  • From Absolute vs. Relative - Explaining CSS Positioning

    Relative positioning uses the same four positioning properties as absolute positioning. But instead of basing the position of the element upon the browser view port, it starts from where the element would be if it were still in the normal flow.