W3C home > Mailing lists > Public > www-style@w3.org > September 2003

Re: attr(x, y)

From: Bert Bos <bert@w3.org>
Date: Mon, 15 Sep 2003 14:21:21 +0200
Message-ID: <16229.44737.958922.833582@lanalana.inria.fr>
To: <www-style@w3.org>

Sigurd Lerstad writes:
> > > Where is the syntax of property value attr(x,y) described?
> > >
> > > In CSS2, there's only attr(x), so attr(x,y) must be new to CSS3? But I
> can't
> > > find where it's described.
> >
> > It is currently meant to go into the Values & Units module.
> 
> Is it long before it's available?
> 
> > The idea is to generalize attr() a bit. The optional second argument can
> > be a type ('string', 'color', 'url', 'length'...) to allow attr() to be
> > used on properties that allow other things than strings. E.g., the type
> > 'url' would indicate that the attribute value is a URL reference relative
> > to the document, because simply taking the attribute as a literal string
> > would give the wrong URL. The default type is 'string'.
> 
> I don't understand why specifying a type would be necessary. The property on
> which attr is set defines the type?

Not always. Imagine this element:

    <FOO TITLE="image" SRC="image" />

and this style:

    FOO { content: attr(TITLE,string) ": " attr(SRC,url) }

which will result in something like this:
            __
           |  |
    image: |__|

Or, more subtly:

    <INLINE LH="14">text with line height "14"</>

with either this style:

    INLINE { line-height: attr(LH,length) }   /* 14px */
or:
    INLINE { line-height: attr(LH,number) }   /* 14 */

> 
> if you have body[TEXT] { color: attr(TEXT)}
> the color attribute knows it has a type of color..
> 
> same with a uri, the background-image property knows it has a uri.
> 
> ??

'Background-image' only accepts a URL (or 'none'), but 'background'
accepts a URL *and* a color. So 'background: attr(X)' on an element
"<FOO X='red'>" is that a color or a URL? How about "<FOO
X='red.png'>"?

> 
> I've also seen 'em' as the second argument, I see the need for that,
> 
> input[size] {width: attr(size, em) }
> 
> but how is that a type?

It's not a type. Do we need this functionality? Note that '12em' is
probably about twice as wide as "<INPUT SIZE=12>" is supposed to be.

> 
> I'm especially interested in that construct, completely implementing form
> controls through css.



Bert
-- 
  Bert Bos                                ( W 3 C ) http://www.w3.org/
  http://www.w3.org/people/bos/                              W3C/ERCIM
  bert@w3.org                             2004 Rt des Lucioles / BP 93
  +33 (0)4 92 38 76 92            06902 Sophia Antipolis Cedex, France
Received on Monday, 15 September 2003 08:21:22 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:54:23 GMT