Accounting for margin with position()
This issue seems so perplexing to me that I feel I must be missing something obvious.
I want to get an element's "left" position within its offset parent with position(). But position() apparently returns the value of the outside of the element's margin. For example:
- <div id="container">
- <p id="par">This is a paragraph of text.</p>
- </div>
And the styles:
- #container
- {
- background-color: #EEEEFF;
- padding: 0;
- }
- #par
- {
- margin: 10px;
- padding: 10px;
- background-color: yellow;
- }
The paragraph's own margin shoves it 10px to the left inside its container. But $('#par).position().left is 0.
I really don't understand why I would ever want the value of the outside of an element's margin when trying to get its position. That's beside the point, though. What technique can I use to get an element's position where it actually starts, i.e., inside the margin?