Noah
Noah

Reputation: 106

Is it possible to absolutely position an element relative to the body, even if a parent element is relatively positioned?

I don't have access to edit HTML, so what I'm left with is a sidebar which I want relatively positioned so I can absolutely position an element inside of it, but I also want a child's child to be absolutely positioned relative to the body, NOT the sidebar.

Visual example:

Sidebar (relative)

| child (absolutely positioned in sidebar)

| child (statically positioned)

| | | | child of child (absolutely positioned relative to the body)

/Sidebar

Upvotes: 2

Views: 43

Answers (1)

bfavaretto
bfavaretto

Reputation: 71939

No, not with CSS. But you can:

  • Use negative values for left and top
  • Maybe use JavaScript to change the element's position within the DOM

Upvotes: 2

Related Questions