w3c / w3c/csswg-drafts

Absolute position respecting the padding of the parent element

Open
#12,929 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

css-position-4
Dominant language
Bikeshed
Stars
4.9k
Forks
816
PR merge metrics
PR metrics pending

Description

CSS Feature Request Proposal: position-context

Subject: Proposal for a new CSS property to enforce padding context for absolutely positioned elements.


1. Introduction and Problem Statement

When an element is positioned absolutely (position: absolute), its positioning coordinates (top, right, bottom, left) are calculated relative to the border box of its nearest positioned ancestor.

This means the element ignores the padding of the parent. To position the child within the padding, the developer is forced to manually duplicate the parent's padding values into the child's positioning properties (e.g., if padding: 20px;, one must use top: 20px; left: 20px;).

This manual adjustment is:

  • Fragile: A change in the parent's padding requires a corresponding manual change on the child.
  • Non-semantic: It breaks the separation of concerns between the parent's spacing and the child's position.
  • Inefficient: It complicates the use of responsive or variable-based padding values.

2. Proposed Solution: The position-context Property

We propose a new CSS property, named position-context, to be applied to the absolutely positioned child element. This property would define the contextual box used for calculating its top, right, bottom, and left offsets.

Proposed Syntax
.child-absolute {
  position: absolute;
  position-context: <value>;
}

Proposed Values for the CSS Property position-context

This table defines the contextual box used for calculating the offsets (top, left, etc.) of an absolutely positioned element. Note: This property is a feature proposal and does not currently exist in standard CSS.

Value Description Contextual Box Used for Positioning
border-box (Default) Coordinates are calculated from the outer edge of the border of the positioned ancestor. (Current standard CSS behavior).
padding-box (NEW) Coordinates are calculated from the inner edge of the padding of the positioned ancestor. (The desired behavior to respect the parent's padding).
content-box Coordinates are calculated from the inner edge of the content area of the positioned ancestor (inside padding and border).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the proposal's description of absolute-positioning offsets and the existing CSS behavior it summarizes. Compare the proposed border-box, padding-box, and content-box contexts with current positioning rules. Done would require resolving the proposal and defining an accepted CSS feature, rather than making a single implementation edit.

Written by the indexing model from the issue text.

Assessment

Tech stack
css
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.