Skip to content

[css-logical][css-images] flow-relative gradients #1724

@jonathantneal

Description

@jonathantneal

When writing right-to-left CSS, I’ve noticed I sometimes need to flip presentational images (usually symbols, like "left" or "right" arrows) and gradients. I’m not sure how to solve the former issue, but I have an idea of how I could solve the later.

I propose this addition to CSS Logical Properties and Values that would allow myself and others to write flow-relative gradients.

The linear gradient syntax is:

linear-gradient() = linear-gradient(
  [ <angle> | to <side-or-corner> ]? ,
    <color-stop-list>
)

And the physical and flow-relative values for <side-or-corner> would be:

<side-or-corner> =
[ [left | right] || [top | bottom] ] |
[ [inline-start | inline-end] || [block-start | block-end ] ]

^ updated to reflect @tabatkins feedback

Using this syntax, I could write:

header {
  background-image: linear-gradient(to inline-end, yellow 0%, blue 100%);
}

And left-to-right page progressions would see the equivalent to:

header {
  background-image: linear-gradient(to right, yellow 0%, blue 100%);
}

While right-to-left page progressions would see the equivalent to:

header {
  background-image: linear-gradient(to left, yellow 0%, blue 100%);
}

I’ve put this into a (probably poorly written) spec: https://jonathantneal.github.io/logical-gradients-spec/

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions