Skip to content

Commit

Permalink
web/core: Add comment about how margin % are calculated
Browse files Browse the repository at this point in the history
This confused me twice now, its time to add a comment so
no one else stumbles into the same trap (:
  • Loading branch information
simonwuelker committed Dec 16, 2023
1 parent 64a6e4a commit cd12454
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crates/web/core/src/css/layout/flow/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,10 @@ impl BlockDimensions {
containing_block: ContainingBlock,
length_resolution_context: length::ResolutionContext,
) -> Self {
// FIXME: replaced elements
// NOTE: This is not a mistake, *both* horizontal and vertical margin percentages are calculated
// with respect to the *width* of the containing block.
// Refer to https://drafts.csswg.org/css2/#margin-properties
let available_length = Length::pixels(containing_block.width());

let resolve_margin = |margin: &values::Margin| {
margin
.map(|p| p.resolve_against(available_length))
Expand Down

0 comments on commit cd12454

Please sign in to comment.