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 8619169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:16:44+00:00 2026-06-12T06:16:44+00:00

I was doing some tests with CSS positioning and I noticed an odd behavior.

  • 0

I was doing some tests with CSS positioning and I noticed an odd behavior.

Let’s say I have an absolutely positioned container div (red). Inside this div I want to place two blocks (green and blue), with a relative position to the container. These blocks should stick to the top and have a 50 pixels distance between them, like below

enter image description here

So I’m thinking I should use top:0px; left:0px; for the first one, to place him near the top left corner. I add 50 to its width for the spacing and I get top:0px; left: 100px; for the second block. (jsfiddle here).

Instead of seeing the expected behavior, I get this positioning

enter image description here

It seems that the second block has its toprelative to the first block, and not to the parent container. So the correct CSS code for the second block should be top: -50px; left: 100px;, like in this fiddle.

This isn’t the first time I noticed this. In some cases, the left property it’s the one at fault, in this case it was top.

Anyway, I know how to fix these problems and get the correct display, but I don’t understand why isn’t it working like I think it should.

It’s very likely that I misunderstood something about this whole absolute/relative positioning, but I don’t know what it is.

  • 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-06-12T06:16:46+00:00Added an answer on June 12, 2026 at 6:16 am

    The second block has its top and left relative to itself, not the first block or the parent container.

    When you position something relatively, its offset values shift it in those directions away from what its original position would have been before you applied relative positioning. The offsets are never based on the positions of its siblings, ancestors or descendants (unless they are auto, which is their initial value).

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

Sidebar

Related Questions

I execute some tests within my application, but before doing that I have to
I have seen some developers write HTML: <div class=test> some content </div> CSS: div.test
I'm doing some tests with new features of CSS3, but this combination only works
I'm doing some tests, but I see no difference when I use or not
I am doing some tests, just to learn (normally i do this in ajax
I'm basically just doing some tests to figure out a good way to write
I was previously working with Ember.StateManager and now I'm doing some tests before I
I'm new in Silverlight and i am doing some tests. With my current test
I'm developing an application with Spring 3. I'm doing some tests with spring batch.
I'm doing some unit tests for an EntityEventListener from NHibernate, and I'm got stuck

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.