Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3800608
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:55:11+00:00 2026-05-19T13:55:11+00:00

I’m trying to understand CSS positioning and I’m having trouble figuring out why a

  • 0

I’m trying to understand CSS positioning and I’m having trouble figuring out why a simple change that apparently should have no effect on the layout is causing a very disruptive change. I’m obviously missing something.

The initial objective was to place an inner div
vertically and horizontally within another div. That was fairly simple:

html, body {
 margin:0;
 padding:0;
 height:100%;
}

div#container {
 position:relative;
 background:#4444ff;
 margin: 0 auto; /* center, not in IE5 */

 height:80%; 
 min-height:80%; 
}

div#childDiv {
 position:absolute;
 background:#ff5555;

 /* next we center it vertically and horizontally */
 width:900px;
 height:600px;
 top:50%;
 margin-top:-300px;
 left:50%;
 margin-left:-450px;
}

…and in the HTML page I used:

<body>
<div id=container>
 <div id=childDiv>
  test
    </div>
</div>


</body>

which worked fine.

The curious part is what happens when I change the position attribute of the #childDiv div from absolute to relative.

My understanding is that first is should not affect the #container div at all since I’m changing only the position of the child element, and second that it should not change the layout since it is the only child element, its parent uses relative position and third I have not specified any offsets (tp, left, etc).

Instead, when I make this change, the parent #container is messed up (shows only up to the half of the viewport instead of 80% height as previously), and the position of #childDiv changes accordingly (also upwards, half outside the viewport).

My questions is: why does that happen? What concepts I’m not taking into account and why was the parent div affected by a change in the children’s position setting?

If I remove #childDiv from within #container and place it inside body, then #container is no longer affected by that change so it seems something is propagating up in the DOM, which is odd to me. I’ve seen the same in firefox, opera, IE and chrome.

I have read W3C’s spec on this topic but I haven’t been able to figure this one out so far…

UPDATE: I created examples in JS fiddle to show the problem. You can see the original is here: jsfiddle.net/7Pr9y/1 and the affected one is here: jsfiddle.net/7Pr9y/3

Thank you!
Eduardo

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:55:12+00:00Added an answer on May 19, 2026 at 1:55 pm

    When something is absolutely positioned, it is taken out of normal flow so its size, margins, etc. do not affect the things around it.

    When something is relatively positioned, it is placed in normal flow (so its size, margins, etc. do affect the things around it) and layout is initially handled as if it were position: static, then it is moved according to the left, right, top and bottom properties.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.