Skip to content

Commit 7ee9894

Browse files
committed
[css-variables] Add some examples to the API section.
1 parent e7ec0e4 commit 7ee9894

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

css-variables/Overview.html

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,36 @@ <h3 id=the-cssvariablesdeclaration-interface><span class=secno>4.2. </span>
828828
<var>varName</var> as its argument, and return the returned value.
829829
Otherwise, do nothing and return the empty string.
830830

831+
<div class=example> For example, given the following style sheet:
832+
<pre>div {
833+
var-foo: 16px;
834+
var-Bar: red;
835+
var-foo-bar: 50%;
836+
}
837+
</pre>
838+
839+
<p> The following lines of script all return something useful:
840+
841+
<pre>el = document.querySelector("div");
842+
print(el.style.var.foo); /* Prints the value of "var-foo" */
843+
print(el.style.var.Bar); /* Prints the value of "var-Bar" */
844+
print(el.style.var["foo-bar"]); /* Prints the value of "var-foo-bar" */
845+
</pre>
846+
847+
<p> On the other hand, the following do not:
848+
849+
<pre>print(el.style.varFoo);
850+
/* Custom properties don’t exist directly on "style" */
851+
852+
print(el.style.varfoo);
853+
/* Not even if the casing matches. */
854+
855+
print(el.style.var.foo-bar);
856+
/* Retrieves "var-foo" and subtracts a JS variable named "bar",
857+
rather than retrieving the value of "var-foo-bar" */
858+
</pre>
859+
</div>
860+
831861
<h2 id=acknowledgments><span class=secno>5. </span> Acknowledgments</h2>
832862

833863
<h2 id=conformance><span class=secno>6. </span> Conformance</h2>
@@ -946,7 +976,7 @@ <h3 id=testing><span class=secno>6.5. </span> Non-experimental
946976
W3C are subject to review and correction by the CSS Working Group.
947977

948978
<p>Further information on submitting testcases and implementation reports
949-
can be found from on the CSS Working Groups website at <a
979+
can be found from on the CSS Working Group's website at <a
950980
href="http://www.w3.org/Style/CSS/Test/">http://www.w3.org/Style/CSS/Test/</a>.
951981
Questions should be directed to the <a
952982
href="http://lists.w3.org/Archives/Public/public-css-testsuite">public-css-testsuite@w3.org</a>

css-variables/Overview.src.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,42 @@ <h3 id='the-cssvariablesdeclaration-interface'>
608608
and return the returned value.
609609
Otherwise, do nothing and return the empty string.
610610

611+
<div class='example'>
612+
For example,
613+
given the following style sheet:
614+
615+
<pre>
616+
div {
617+
var-foo: 16px;
618+
var-Bar: red;
619+
var-foo-bar: 50%;
620+
}
621+
</pre>
622+
623+
The following lines of script all return something useful:
624+
625+
<pre>
626+
el = document.querySelector("div");
627+
print(el.style.var.foo); /* Prints the value of "var-foo" */
628+
print(el.style.var.Bar); /* Prints the value of "var-Bar" */
629+
print(el.style.var["foo-bar"]); /* Prints the value of "var-foo-bar" */
630+
</pre>
631+
632+
On the other hand, the following do not:
633+
634+
<pre>
635+
print(el.style.varFoo);
636+
/* Custom properties don't exist directly on "style" */
637+
638+
print(el.style.varfoo);
639+
/* Not even if the casing matches. */
640+
641+
print(el.style.var.foo-bar);
642+
/* Retrieves "var-foo" and subtracts a JS variable named "bar",
643+
rather than retrieving the value of "var-foo-bar" */
644+
</pre>
645+
</div>
646+
611647

612648
<h2>
613649
Acknowledgments</h2>

0 commit comments

Comments
 (0)