Skip to content

Commit 0c5b72d

Browse files
committed
Start replacing the @var syntax with the data-* syntax.
1 parent ba656c6 commit 0c5b72d

2 files changed

Lines changed: 132 additions & 49 deletions

File tree

css-variables/Overview.html

Lines changed: 97 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222

2323
<h1>CSS Variables Module Level 1</h1>
2424

25-
<h2 class="no-num no-toc" id=longstatus-date>Editor's Draft 3 October 2011</h2>
25+
<h2 class="no-num no-toc" id=longstatus-date>Editor's Draft 26 October
26+
2011</h2>
2627

2728
<dl>
2829
<dt>This version:
2930

3031
<dd><a
31-
href="http://www.w3.org/TR/2011/ED-css-variables-20111003/">http://dev.w3.org/csswg/css-variables/</a>
32+
href="http://www.w3.org/TR/2011/ED-css-variables-20111026/">http://dev.w3.org/csswg/css-variables/</a>
3233
<!--<dt>Latest version:
3334
<dd><a href="http://www.w3.org/TR/css-variables/">http://www.w3.org/TR/css-variables/</a>-->
3435

@@ -206,18 +207,19 @@ <h2 id=intro><span class=secno>1. </span> Introduction</h2>
206207
error-prone, since it's scattered throughout the CSS file (and possibly
207208
across multiple files), and may not be amenable to Find-and-Replace.
208209

209-
<p>This module introduces <b>Variables</b>, which allow a value to be
210-
assigned to a name, which may then be used in place of the value elsewhere
211-
in the document. This makes it easier to read large files, as
212-
seemingly-arbitrary values now have informative names, and makes editting
213-
such files much easier and less error-prone, as one only has to change the
214-
value once, at the variable definition site, and the change will propagate
215-
to all uses of that variable automatically.
210+
<p>This module introduces a family of custom user-defined properties known
211+
collectively as <b>Variables</b>, which allow an author to assign values
212+
to a property with an author-chosen name, and then use those values in
213+
other properties elsewhere in the document. This makes it easier to read
214+
large files, as seemingly-arbitrary values now have informative names, and
215+
makes editting such files much easier and less error-prone, as one only
216+
has to change the value once, at the variable definition site, and the
217+
change will propagate to all uses of that variable automatically.
216218

217219
<h3 id=placement><span class=secno>1.1. </span> Module Interactions</h3>
218220

219-
<p>This module defines a new type of primitive value, the <b>Variable</b>,
220-
which is accepted by all properties.
221+
<p>This module defines a new type of primitive value, the <a
222+
href="#variable"><b>Variable</b></a>, which is accepted by all properties.
221223

222224
<h3 id=values><span class=secno>1.2. </span> Values</h3>
223225

@@ -234,39 +236,81 @@ <h3 id=values><span class=secno>1.2. </span> Values</h3>
234236

235237
<h2 id=defining-variables><span class=secno>2. </span> Defining Variables</h2>
236238

237-
<p>A &lsquo;<code class=css>@var</code>&rsquo; rule defines a variable and
238-
assigns a value to it. It consists of the at-keyword &lsquo;<code
239-
class=css>@var</code>&rsquo; followed by a variable name (an identifier
240-
starting with the "$" character), followed by the value and finally
241-
terminated with a semi-colon. The result of this rule is that the given
242-
value is assigned to the given variable name.
239+
<p>A <dfn id=variable>variable</dfn> is defined by assigning a value to a
240+
property whose name starts with the prefix "data-" (this class of
241+
properties will be referred to <a href="#data-property"><i>data
242+
properties</i></a>). <em>Any</em> property with the "data-" prefix is
243+
defined to be valid but meaningless, and will never be given a specific
244+
meaning or effect by a CSS specification or user agent; this is similar to
245+
the <code>data-*</code> family of custom attributes in HTML.
243246

244-
<p>
247+
<table class=propdef>
248+
<tbody>
249+
<tr>
250+
<th>Name:
251+
252+
<td><dfn id=data-property
253+
title="data property|data properties">data-*</dfn>
254+
255+
<tr>
256+
<th>Values:
257+
258+
<td>
259+
<div class=issue>Figure this out - restricted or wide-open</div>
260+
261+
<tr>
262+
<th>Initial:
263+
264+
<td>
265+
<div class=issue>???</div>
245266

246-
<p class=note>I chose the $ prefix over the var() function for terseness.
247-
We should try to avoid nesting functions as much as reasonable, as it's
248-
hard to read. The $ is required in the variable definition as well as the
249-
variable use for consistency - every instance of the variable name within
250-
CSS has the same form.
267+
<tr>
268+
<th>Applies To:
269+
270+
<td>all elements
271+
272+
<tr>
273+
<th>Inherited:
274+
275+
<td>yes
276+
277+
<tr>
278+
<th>Computed Value:
279+
280+
<td>specified value
281+
282+
<tr>
283+
<th>Media:
284+
285+
<td>all
286+
</table>
251287

252288
<div class=example>
253289
<p>This variables declaration:</p>
254290

255-
<pre>@var $header-color #06c;</pre>
291+
<pre>
292+
:root {
293+
data-header-color: #06c;
294+
}</pre>
256295

257-
<p>declares a variable named "$header-color", and assigns to it the value
258-
"#06c". This can then be used in any place where that value would be
259-
valid, such as:
296+
<p>declares a <a href="#data-property"><i>data property</i></a> named
297+
"data-header-color" on the root element, and assigns to it the value
298+
"#06c". This property is then inherited to the elements in the rest of
299+
the document, and its value can then be used in any place where it would
300+
be valid, such as:
260301

261-
<pre>h1 { background-color: $header-color; }</pre>
302+
<pre>h1 { background-color: data(header-color); }</pre>
262303

263304
<p>The preceding rule is equivalent to writing &lsquo;<code
264305
class=css>background-color: #06c;</code>&rsquo;, except that the variable
265-
name makes the origin of the color clearer, and if $header-color is used
266-
elsewhere in the stylesheet, all of the uses can be updated at once by
267-
changing the variable declaration.</p>
306+
name makes the origin of the color clearer, and if &lsquo;<code
307+
class=css>data(header-color)</code>&rsquo; is used elsewhere in the
308+
stylesheet, all of the uses can be updated at once by changing the
309+
variable declaration.</p>
268310
</div>
269311

312+
<p class=issue>Finish replacing the rest of this section.
313+
270314
<p>Defined variables are available to all stylesheets in the document.
271315
Thus, using &lsquo;<code class=css>@import</code>&rsquo; to include a
272316
stylesheet also includes all variables defined in the stylesheet (and
@@ -278,14 +322,6 @@ <h2 id=defining-variables><span class=secno>2. </span> Defining Variables</h2>
278322
imported within scoped stylesheets are only available within the scoped
279323
stylesheet and any imported stylesheets.
280324

281-
<p class=note>Making all variables global is the simplest solution that
282-
works, and is consistent with other at-rules that define names, like
283-
@font-face and @counter-style - the web seems to get by great on "ad-hoc
284-
scoping" via adding short prefixes. If it is shown that we need a more
285-
complex scoping solution in the future, I believe we can do so via a
286-
general scoping/namespacing mechanism that applies to all the at-rules
287-
that define names.
288-
289325
<p>A &lsquo;<code class=css>@var</code>&rsquo; rule is <dfn
290326
id=inactive-var-rule>inactive</dfn> if it's present in a disabled or
291327
alternate stylesheet, a stylesheet with a media query that evaluates to
@@ -898,6 +934,12 @@ <h2 class=no-num id=index>Index</h2>
898934
<li>authoring tool, <a href="#authoring-tool"
899935
title="authoring tool"><strong>6.2.</strong></a>
900936

937+
<li>data properties, <a href="#data-property"
938+
title="data properties"><strong>2.</strong></a>
939+
940+
<li>data property, <a href="#data-property"
941+
title="data property"><strong>2.</strong></a>
942+
901943
<li>inactive, <a href="#inactive-var-rule"
902944
title=inactive><strong>2.</strong></a>
903945

@@ -920,6 +962,8 @@ <h2 class=no-num id=index>Index</h2>
920962
title="style sheet, as conformance class"><strong>6.2.</strong></a>
921963
</ul>
922964

965+
<li>variable, <a href="#variable" title=variable><strong>2.</strong></a>
966+
923967
<li><a href="#variablerule"><code>VARIABLE_RULE</code></a>, <a
924968
href="#variablerule" title="VARIABLE_RULE"><strong>4.2.1.</strong></a>
925969
</ul>
@@ -946,6 +990,20 @@ <h2 class=no-num id=property-index>Property index</h2>
946990
<th>Media
947991

948992
<tbody>
993+
<tr>
994+
<th><span class=property>data-*</span>
995+
996+
<td>Figure this out - restricted or wide-open
997+
998+
<td>???
999+
1000+
<td>all elements
1001+
1002+
<td>yes
1003+
1004+
<td>specified value
1005+
1006+
<td>all
9491007
</table>
9501008
<!--end-properties-->
9511009
</html>

css-variables/Overview.src.html

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ <h2 id="intro">
6161

6262
<p>Large documents or applications (and even small ones) can contain quite a bit of CSS. Many of the values in the CSS file will be duplicate data; for example, a site may establish a color scheme and reuse three or four colors throughout the site. Altering this data can be difficult and error-prone, since it's scattered throughout the CSS file (and possibly across multiple files), and may not be amenable to Find-and-Replace.</p>
6363

64-
<p>This module introduces <b>Variables</b>, which allow a value to be assigned to a name, which may then be used in place of the value elsewhere in the document. This makes it easier to read large files, as seemingly-arbitrary values now have informative names, and makes editting such files much easier and less error-prone, as one only has to change the value once, at the variable definition site, and the change will propagate to all uses of that variable automatically.</p>
64+
<p>This module introduces a family of custom user-defined properties known collectively as <b>Variables</b>, which allow an author to assign values to a property with an author-chosen name, and then use those values in other properties elsewhere in the document. This makes it easier to read large files, as seemingly-arbitrary values now have informative names, and makes editting such files much easier and less error-prone, as one only has to change the value once, at the variable definition site, and the change will propagate to all uses of that variable automatically.</p>
6565

6666
<h3 id="placement">
6767
Module Interactions</h3>
@@ -82,25 +82,50 @@ <h3 id="values">
8282
<h2 id="defining-variables">
8383
Defining Variables</h2>
8484

85-
<p>A ''@var'' rule defines a variable and assigns a value to it. It consists of the at-keyword ''@var'' followed by a variable name (an identifier starting with the "$" character), followed by the value and finally terminated with a semi-colon. The result of this rule is that the given value is assigned to the given variable name.<p>
86-
87-
<p class='note'>I chose the $ prefix over the var() function for terseness. We should try to avoid nesting functions as much as reasonable, as it's hard to read. The $ is required in the variable definition as well as the variable use for consistency - every instance of the variable name within CSS has the same form.</p>
85+
<p>A <dfn>variable</dfn> is defined by assigning a value to a property whose name starts with the prefix "data-" (this class of properties will be referred to <i>data properties</i>). <em>Any</em> property with the "data-" prefix is defined to be valid but meaningless, and will never be given a specific meaning or effect by a CSS specification or user agent; this is similar to the <code>data-*</code> family of custom attributes in HTML.</p>
86+
87+
<table class='propdef'>
88+
<tr>
89+
<th>Name:</th>
90+
<td><dfn id='data-property' title='data property|data properties'>data-*</dfn>
91+
<tr>
92+
<th>Values:
93+
<td><div class='issue'>Figure this out - restricted or wide-open</div>
94+
<tr>
95+
<th>Initial:
96+
<td><div class='issue'>???</div>
97+
<tr>
98+
<th>Applies To:
99+
<td>all elements
100+
<tr>
101+
<th>Inherited:
102+
<td>yes
103+
<tr>
104+
<th>Computed Value:
105+
<td>specified value
106+
<tr>
107+
<th>Media:
108+
<td>all
109+
</table>
88110

89111
<div class=example>
90112
<p>This variables declaration:</p>
91113

92-
<pre>@var $header-color #06c;</pre>
114+
<pre>
115+
:root {
116+
data-header-color: #06c;
117+
}</pre>
93118

94-
<p>declares a variable named "$header-color", and assigns to it the value "#06c". This can then be used in any place where that value would be valid, such as:
119+
<p>declares a <i>data property</i> named "data-header-color" on the root element, and assigns to it the value "#06c". This property is then inherited to the elements in the rest of the document, and its value can then be used in any place where it would be valid, such as:
95120

96-
<pre>h1 { background-color: $header-color; }</pre>
121+
<pre>h1 { background-color: data(header-color); }</pre>
97122

98-
<p>The preceding rule is equivalent to writing ''background-color: #06c;'', except that the variable name makes the origin of the color clearer, and if $header-color is used elsewhere in the stylesheet, all of the uses can be updated at once by changing the variable declaration.</p>
123+
<p>The preceding rule is equivalent to writing ''background-color: #06c;'', except that the variable name makes the origin of the color clearer, and if ''data(header-color)'' is used elsewhere in the stylesheet, all of the uses can be updated at once by changing the variable declaration.</p>
99124
</div>
100125

101-
<p>Defined variables are available to all stylesheets in the document. Thus, using ''@import'' to include a stylesheet also includes all variables defined in the stylesheet (and makes all variables declared outside available within the stylesheet, if applicable). ''@var'' rules present in disabled or alternate stylesheets do not define variables. Scoped stylesheets are an exception to this: variables defined in the global scope are available within a scoped stylesheet, but variables defined or imported within scoped stylesheets are only available within the scoped stylesheet and any imported stylesheets.</p>
126+
<p class='issue'>Finish replacing the rest of this section.</p>
102127

103-
<p class='note'>Making all variables global is the simplest solution that works, and is consistent with other at-rules that define names, like @font-face and @counter-style - the web seems to get by great on "ad-hoc scoping" via adding short prefixes. If it is shown that we need a more complex scoping solution in the future, I believe we can do so via a general scoping/namespacing mechanism that applies to all the at-rules that define names.</p>
128+
<p>Defined variables are available to all stylesheets in the document. Thus, using ''@import'' to include a stylesheet also includes all variables defined in the stylesheet (and makes all variables declared outside available within the stylesheet, if applicable). ''@var'' rules present in disabled or alternate stylesheets do not define variables. Scoped stylesheets are an exception to this: variables defined in the global scope are available within a scoped stylesheet, but variables defined or imported within scoped stylesheets are only available within the scoped stylesheet and any imported stylesheets.</p>
104129

105130
<p>A ''@var'' rule is <dfn id='inactive-var-rule'>inactive</dfn> if it's present in a disabled or alternate stylesheet, a stylesheet with a media query that evaluates to false, or is present within a conditional rule group [[CSS3CONDITIONAL]] whose condition evaluates to false. <i>Inactive</i> ''@var'' rules do not define variables. All other ''@var'' rules are <dfn id='active-var-rule'>active</dfn>.</p>
106131

0 commit comments

Comments
 (0)