Skip to content

Add the aspect-ratio property - #205

Merged
TylerBrinks merged 1 commit into
TylerBrinks:masterfrom
jhaygood86:feature/aspect-ratio
Jul 23, 2026
Merged

Add the aspect-ratio property#205
TylerBrinks merged 1 commit into
TylerBrinks:masterfrom
jhaygood86:feature/aspect-ratio

Conversation

@jhaygood86

Copy link
Copy Markdown
Contributor

Feature

Adds the aspect-ratio property (CSS Sizing 4 §4.1):

aspect-ratio: [ auto || <ratio> ]
<ratio> = <number [0,∞]> [ / <number [0,∞]> ]?

auto and the ratio may appear in either order, or either alone (the || combinator).

Implementation

A dedicated AspectRatioValueConverter validates the grammar and preserves the authored text. A denominator defaults to 1 when omitted, negative numbers are rejected, and auto may appear before or after the ratio but not twice.

Registered as AspectRatioProperty in PropertyFactory.

Tests

18 cases in PropertyTests/AspectRatioProperty.cs:

  • legal: auto, 16 / 9, 16/9, a single <number>, auto 16 / 9, 16 / 9 auto, decimals
  • illegal: none, 16 /, / 9, three terms, negative, auto auto, two bare numbers, a length instead of a number
  • inherit/initial

The legal and illegal cases fail on master (the property is unknown). The full suite (1263 existing tests) stays green, and all seven target frameworks build with no new warnings.

aspect-ratio: [ auto || <ratio> ] (CSS Sizing 4 4.1), where
<ratio> = <number [0,inf]> [ / <number [0,inf]> ]?, had no support.

Add AspectRatioValueConverter, which validates the grammar - auto, a
ratio, or both in either order - and preserves the authored text, and an
AspectRatioProperty registered in PropertyFactory. Negative numbers, a
missing denominator, a bare slash, three terms and non-number terms are
all rejected.
@jhaygood86
jhaygood86 marked this pull request as ready for review July 22, 2026 22:41
@TylerBrinks
TylerBrinks merged commit b20dcb2 into TylerBrinks:master Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants