Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Relative positioning without updating flow

Tags:

css

How can I place an object without updating the flow of other objects, but specify coordinates relative to the parent?

To clarify,

position: relative; top: -30px; left: 600px; updates the flow of following objects, position: absolute; top: -30px; left: 600px; doesn't update flow but is relative positioning.

I need not to update the flow, but to specify relative positioning. I can also use Javascript solution.

EDIT

I think a better example would be this: I have a document, I now want to place a <p> which displays over the existing document without changing the flow (think of a watermark). I also have some specific <div class='abc'>, with respect to which I know that I want to place the new <p> at say coordinates (600,-30).

like image 904
KalEl Avatar asked Nov 14 '09 14:11

KalEl


People also ask

Does position relative take element out of flow?

Relative positioning and flowIf you give an item relative positioning with position: relative , it remains in flow. However, you are then able to use the offset values to push it around.

Is it bad to use position relative in CSS?

Yes. You will not be able to work with absolutely positioned elements any more, for example - the absolute positioning will always be relative to the parent element, which is almost never the desired result.

Does absolute position Remove from flow?

Absolutely positioned elements are removed entirely from the document flow. That means they have no effect at all on their parent element or on the elements that occur after them in the source code. An absolutely positioned element will therefore overlap other content unless you take action to prevent it.

When using position fixed What will the element always be positioned relative to?

An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled. The top, right, bottom, and left properties are used to position the element.


2 Answers

Apply position: relative; to the parent element, and use position: absolute; top: whatever; left: whatever on the child element. You can also use a z-index: something to make the original content of the parent element overlap the child element with the absolute positioning.

Not sure if I totally get what you mean, though... And I think this is supposed to be on http://www.doctype.com/, because it isn't really about programming.

like image 152
Douwe Maan Avatar answered Sep 18 '22 23:09

Douwe Maan


I think what I was looking for is width:0;height:0; so that the flow after is not realigned because of this element. I wasn't sure initially however, that the object will be displayed at all if I set it to have 0 dimensions.

like image 29
KalEl Avatar answered Sep 17 '22 23:09

KalEl