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

  • SEARCH
  • Home
  • 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 1035447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:32:37+00:00 2026-05-16T14:32:37+00:00

Why does an html element (such as a div) that has been styled with

  • 0

Why does an html element (such as a div) that has been styled with

position: relative;
top: -50px;

Still force the parent element to have the same size as if the relatively positioned element were not shifted?

Let me provide an example (live example found at http://jsbin.com/ohebi4/2/edit)

<html>
<head>
  <style>
      article, aside, figure, footer, header, hgroup,
      menu, nav, section { display: block; }

      .parent{ position: relative; background-color: #000000; float: left; border: 1px solid red; }
      .child1{ float: left; background-color: #888888;}
      .child2{ float: left; background-color: #CCCCCC; }

      .subchild{ position: relative; top: -45px; height: 30px; border: 1px solid green;}
      .subchild2{ height: 30px; border: 1px solid green;}
    </style>
</head>
<body>

  <div style='clear: both; height: 50px;'></div>
  <div class='parent'>
    <div class='child1'>regular content</div>
    <div class='child2'>content of child 2</div>
  </div>
  <div>Sample A</div>

  <div style='clear: both; height: 50px;'></div>
  <div class='parent'>
    <div class='child1'><div class='subchild2'>subchild</div></div>
    <div class='child2'>content of child 2</div>
  </div>
  <div>Sample B</div>

  <div style='clear: both; height: 50px;'></div>
  <div class='parent'>
    <div class='child1'><div class='subchild'>subchild</div></div>
    <div class='child2'>content of child 2</div>
  </div>
  <div>Sample C</div>  

  <div style='clear: both; height: 50px;'></div>
  <div class='parent'>
    <div class='child1'><span>child 1</span><div class='subchild'>subchild</div></div>
    <div class='child2'>content of child 2</div>
  </div>
  <div>Sample D</div>
</body>
</html>

The above markup creates a page that looks like this:

alt text

Sample A: Just a couple of divs inside a parent div, with normal content and flow

Sample B: Added a subchild div, with a height of 30px. As expected, it changes the height of the parent, thus revealing the black background beneath “content of child b”

Sample C: The subchild is repositions with position:relative. Note how even though this element is shifted above everything, it still contributes to the height of the parent, thus keeping the black background revealed

Sample D: Problem in sample C excacerbated by added a span before subchild div.

The behavior in A and B I understand. What I do not understand is the behavior in C and D. If the element that makes the parent taller is repositioned such that it isn’t in that space anymore … why does it still make the parent taller?

I expect (incorrectly, obviously), that example C (and D) would look identical to A, with the addition of the green “subchild” box above it.

Can anyone explain to me why this is, and how to not have a relatively placed element affect the dimensions of the parent like this?

  • 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-16T14:32:38+00:00Added an answer on May 16, 2026 at 2:32 pm

    You’ll have to set:

    position:absolute;
    

    to have the .subchild not be put into the normal flow. As you already have the .parent set to position:relative;, you don’t need to do anything else.


    According to this, position:relative; is still calculated into normal flow. position:absolute; will make it NOT calculated into normal flow and will use the top-left of the first parent tag with position:relative; as the origin. (If no parents are relative, then it assumes the viewport, and will act like it is fixed.) position:fixed; always uses the viewport top-left as the origin.

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

Sidebar

Related Questions

I've read http://dbaspot.com/sqlserver-programming/463313-32-bit-clr-procedure-64-bit-sql-server.html Does that mean it's not possible to run a 32 bits
I am loading contents into a same domain iframe. Does the html file that
Does the IFRAME's onload event fire when the HTML has fully downloaded, or only
I've heard that putting a block element inside a inline element is a HTML
I have some data that I need to associate with specific element such as
How does HTML work? Does it get parsed, compiled and then executed? Does it
Is there an equivalent way of achieving what HTML Tidy does to HTML code
I have a form in simple HTML and does not use strut tags. When
Ryan Bates' nifty_scaffolding, for example, does this edit.html.erb <%= render :partial => 'form' %>
Does anyone know how to pass html attributes like data-date to the Html.TextBox()?? It

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.