Skip to content

Fix 0% losing its percent unit during CSS serialization#202

Merged
FlorianRappl merged 1 commit intoAngleSharp:develfrom
jafin:fix/preserve-percent-unit-on-zero-values
Mar 28, 2026
Merged

Fix 0% losing its percent unit during CSS serialization#202
FlorianRappl merged 1 commit intoAngleSharp:develfrom
jafin:fix/preserve-percent-unit-on-zero-values

Conversation

@jafin
Copy link
Copy Markdown
Contributor

@jafin jafin commented Mar 27, 2026

Types of Changes

Prerequisites

Please make sure you can check the following two boxes:

  • I have read the CONTRIBUTING document
  • My code follows the code style of this project

Contribution Type

What types of changes does your code introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue, please reference the issue id)
  • New feature (non-breaking change which adds functionality, make sure to open an associated issue first)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed

Description

Fix 0% losing its percent unit during CSS serialization

CssLengthValue.CssText unconditionally stripped all units when the
numeric value was zero. Per CSS spec, 0 is valid without a unit for
values, but values must always include the %
sign since 0% and 0 have different semantic meanings (e.g. flex-basis).

Resolves #172

CssLengthValue.CssText unconditionally stripped all units when the
numeric value was zero. Per CSS spec, 0 is valid without a unit for
<length> values, but <percentage> values must always include the %
sign since 0% and 0 have different semantic meanings (e.g. flex-basis).
@jafin
Copy link
Copy Markdown
Contributor Author

jafin commented Mar 27, 2026

The MDN docs I may misunderstand, or they don't adhere to their own docs.

image

https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/transform-origin

So not really certain what the correct answer is here.

Edit: ok here is what I understand.

<body style="transform-origin: left 5px -3px;">
const value = getComputedStyle(document.body).transformOrigin;
console.log(value);

Computed style usually resolves percentages into pixels, based on the element’s size.
But percentage is not incorrect. But the value without a px or % is still less correct.

@FlorianRappl
Copy link
Copy Markdown
Contributor

That's correct - there is a difference between the computed style and the default interpretation.

@jafin
Copy link
Copy Markdown
Contributor Author

jafin commented Mar 27, 2026

I don't have any further advice on a resolution, I'll close this.

@jafin jafin closed this Mar 27, 2026
@FlorianRappl
Copy link
Copy Markdown
Contributor

Why close it?

@FlorianRappl FlorianRappl reopened this Mar 28, 2026
@FlorianRappl FlorianRappl merged commit 5a1d528 into AngleSharp:devel Mar 28, 2026
9 checks passed
@jafin
Copy link
Copy Markdown
Contributor Author

jafin commented Mar 28, 2026

@FlorianRappl sorry I misunderstood your response. I didn't see a way forward to resolve the desired output for the example you presented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing unit on 0 values

2 participants