W3C home > Mailing lists > Public > www-style@w3.org > April 2011

[css3] linear-gradient() proposal

From: Andrew Fedoniouk <andrew.fedoniouk@live.com>
Date: Sat, 2 Apr 2011 15:07:08 -0700
Message-ID: <BLU159-ds211B8B1BCAEA482AA762ABF8A10@phx.gbl>
To: <www-style@w3.org>
I propose to change <linear-gradient> production defined here:
to the following.

Rendering of various linear gradients
covered by the proposal. (There is a debug rendering there showing
gradient vector used in each particular case.)

The proposed linear-gradient() "function" is:

    = linear-gradient( [<position>,] [<angle>,] <color-stop>[, 
<color-stop>]+ );

Where <position> is either one of these:

a)     [top | bottom] || [left | right]
b)     <length> [ <length> ]
c)     <length> '/' <length> <length> '/' <length>

Case (a) defines simple top-to-bottom and diagonal cases.
Cases (b) and (c) define cases when gradient is contained inside
some arbitrary rectangle.

Meaning of case (c):
  x-position / x-offset  y-position / y-offset

x/y-positions define start position of the gradient vector and
x/y-offsets define offset of the end position from start position.

When 'angle' is provided then there are following combinations possible:

- angle.a) no position is given at all:
       rendering follows these rules: 

- angle.b) start position is provided but no offset:
       rendering follows the rule above except of the gradient vector starts 
in 'start' point

- angle.c) both start and offset are provided:
       start defines center of the ellipse and offset defines two radii of 
the ellipse.
       diagonal/line that is drawn using angle through the start and 
connecting points on the outline
       of the ellipse is the gradient vector.

Case (angle.c) allows to animate angles in gradients without "wobbling"
(when ellipse is set to circle)

Here are styles used to produce that rendering above:

  @const START: rgb(255,0,0);
  @const END: rgba(0,0,255,0.5);

  /* simple top to bottom case */
    background: linear-gradient(top, @START, @END);

/* simple diagonal case from top/left to bottom/right */
     background: linear-gradient(top left, @START, @END);

  /* simple gradient in fixed are at bottom/right corner */
    background: linear-gradient(100%/-80px 100%/-80px, @START, @END);
  /* simple angled gradient covering the area in full */
    background: linear-gradient(45deg, @START, @END);

  /* angled gradient from the given position */
    background: linear-gradient(25% 25%, 45deg, @START, @END);

  /* angled gradient located in fixed circle at left/top corner,
     angle rotation will not change length of the gradient vector*/
    background: linear-gradient(40px/40px 40px/40px, 45deg, @START, @END);

This way the gradient function will cover all practical cases where linear 
are required.

I also propose to limit color stops by using only percentages for defining
stop offsets:
<color-stop> = <color> [ <percentage> ]If it is possible to define 
explicitly start/end positions then lengths are not
needed there.

Andrew Fedoniouk

Received on Saturday, 2 April 2011 22:07:46 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:49:58 UTC