Relatively position an element without it taking up space in document flow

Web_Designer picture Web_Designer · May 18, 2011 · Viewed 88k times · Source

How can I relatively position an element, and have it not take up space in the document flow?

Answer

Nightfirecat picture Nightfirecat · May 18, 2011

What you're trying to do sounds like absolute positioning. On the other hand, you can, however, make a pseudo-relative element, by creating a zero-width, zero-height, relatively positioned element, essentially solely for the purpose of creating a reference point for position, and an absolutely positioned element within that:

<div style="position: relative; width: 0; height: 0">
    <div style="position: absolute; left: 100px; top: 100px">
        Hi there, I'm 100px offset from where I ought to be, from the top and left.
    </div>
</div>