W3C home > Mailing lists > Public > www-style@w3.org > November 2010

Re: [css3-background] New use case for background-position-x (&y!)

From: Aryeh Gregor <Simetrical+w3c@gmail.com>
Date: Wed, 10 Nov 2010 14:09:37 -0500
Message-ID: <AANLkTimtqWK24mr3EYx0m4g3Lws_3GsywmmqK_z3=CAu@mail.gmail.com>
To: Lee Kowalkowski <lee.kowalkowski@googlemail.com>
Cc: "Tab Atkins Jr." <jackalmage@gmail.com>, Brad Kemper <brad.kemper@gmail.com>, www-style@w3.org
On Tue, Nov 9, 2010 at 6:45 PM, Lee Kowalkowski
<lee.kowalkowski@googlemail.com> wrote:
> Why do the limitations of a technique disturb you?  Everything has
> limitations.

The point is this: you want spriting to be easier.  Great, everyone
agrees that spriting (or some equivalent) should be easier.  Given
that, what are the best features we can add to the standards to make
spriting as easy as possible?

Overall, media fragments are a much better solution than using
background-position and clipping.  Sprited images specified with media
fragments will work much better with all the other CSS background
properties, like background-size and so on, because it will behave as
though the cropped portion is the whole image, and it will work in a
wider variety of use-cases (like tiling).  They'll work in HTML <img>
too, and places in CSS other than backgrounds, and in most cases
they'll take fewer lines of CSS to use (or none).  Once media
fragments are available, authors will probably not *want* to use
background-position for spriting.

Therefore, given that media fragments are already being added to the
platform, it's not enough for you to argue that background-position-x
would be useful *now*.  It's not going to be implemented by all
browsers *now* no matter what.  Even if it were added to the spec now,
it would be several years before you could use it reliably.  So to
justify adding it to the spec, you have to argue that it would *still*
be useful several years from now -- for instance, after media
fragments are already usable.  If media fragments are usable, would
you still want to use this?

That's why people are pointing out the limitations of
background-position for spriting.  The point is that every feature
takes some resources to spec and implement, so we want to focus on
only the best solutions.  If media fragments will obsolete other
spriting techniques, then we don't want to waste effort on improving
existing spriting techniques when they're obsolescent anyway.  If you
want background-position to be improved for spriting, you have to
argue that it will *still* be useful *despite* media fragments.

I can't say for sure, but I don't think you'd want to use
background-position for sprites at all, if media fragments were
available.  Presumably you're writing your card game in JavaScript,
and creating the cards with something like

    someDiv.class = "suit-" + suitNum + " rank-" + rank;

plus 18 CSS rules even if you had this feature.  But if you had media
fragments, you could dispense with the CSS entirely, and instead do
something like

    someImg.src = "myimage.png#xywh=" + [suitNum * imageWidth, rank *
imageHeight, imageWidth, imageHeight].join(",");

Then you don't need any CSS at all, and you might not even need to add
any extra lines of JavaScript.  Certainly you should need to add less
than ten lines of JS net, as far as I can imagine.  So a feature that
does what you want is already mostly specced and will likely start
being implemented soon.  You don't *need* background-position-x or -y
in the long term.

(That said, if Trident and WebKit do implement this without a prefix,
it's probably worth adding to some spec on that basis alone, unless
they're willing to drop support.  Does anyone have a test-case showing
that they implement it?  Is it prefixed, maybe?)
Received on Wednesday, 10 November 2010 19:10:31 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:38:40 UTC