Skip to content

Commit f1f7667

Browse files
committed
[css-content] Fixes w3c#308. Opinionatedly fixes w3c#216. Removes the explicit <image> list (weakly duplicating the functionality of image().) Separates out the one-image case from the content-list case in the grammar. Better defines how both cases work. Also minorly reformats/rephrases the <<string>> section.
1 parent 27fd4e3 commit f1f7667

File tree

1 file changed

+117
-80
lines changed

1 file changed

+117
-80
lines changed

css-content/Overview.bs

Lines changed: 117 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,30 @@ Introduction</h2>
8585
Inserting and replacing content with the 'content' property</h2>
8686

8787
<pre class='propdef'>
88-
Name: content
89-
Value: [ <<image>> ',' ]* [ normal | none | <<content-list>> ] [/ <<string>> ]?
90-
Initial: normal
91-
Applies To: ''::before'', ''::after'', ''::marker'', and page margin boxes. Image and url values can apply to all elements.
92-
Inherited: no
93-
Percentages: n/a
94-
Computed Value: As specified below.
95-
Media: all
88+
Name: content
89+
Value: normal | none | [ <<content-replacement>> | <<content-list>> ] [/ <<string>> ]?
90+
Initial: normal
91+
Applies To: all elements, tree-abiding pseudo-elements, and page margin boxes
92+
Inherited: no
93+
Percentages: n/a
94+
Computed Value: As specified below
95+
Media: all
9696
</pre>
9797

9898

99-
The 'content' property dictates what is rendered inside the element or pseudo-element.
100-
It takes a comma separated list of URIs,
101-
followed by a space separated list of tokens,
102-
followed by an optional slash and string indicating alternative text.
103-
If there are multiple URIs provided,
104-
then each is tried in turn until a value which is both available and supported is found.
105-
The last value is used as a fallback if the others fail.
99+
The 'content' property dictates what is rendered inside an element or pseudo-element.
100+
101+
For elements, it has only one purpose:
102+
specifying that the element renders as normal,
103+
or replacing the element with an image
104+
(and possibly some associated "alt text").
105+
106+
For pseudo-elements and margin boxes,
107+
it is more powerful.
108+
It controls whether the element renders at all,
109+
can replace the element with an image,
110+
or replace it with arbitrary inline content
111+
(text and images).
106112

107113
<dl>
108114
<dt><dfn>normal</dfn>
@@ -120,22 +126,81 @@ Inserting and replacing content with the 'content' property</h2>
120126

121127
In neither case does it prevent any pseudo-elements which have this element or pseudo-element as an <a>originating element</a> from being generated.
122128

129+
<dt><dfn><<content-replacement>></dfn>
130+
<dd id=replaced>
131+
Equal to:
132+
133+
<pre class=prod><<image>></pre>
134+
135+
Makes the element or pseudo-element a <a>replaced element</a>,
136+
filled with the specified <<image>>.
137+
Its normal contents are suppressed
138+
and do not generate boxes,
139+
as if they were ''display: none''.
140+
141+
If the <<image>> represents an <a>invalid image</a>,
142+
then it must be treated as instead representing an image with zero intrinsic width and height,
143+
filled with transparent black.
144+
145+
Issue: The above <a>invalid image</a> behavior appears to be what Chrome is doing.
146+
Is this okay?
147+
Is there a better behavior we can/should use?
148+
149+
Issue: "Zero intrinsic width and height" gives it an undefined aspect ratio,
150+
and sizing behavior is thus... undefined.
151+
At least, if you give it an explicit width or height,
152+
the other dimension remains at zero in Chrome.
153+
This might need to be explicitly defined over in the Images spec;
154+
needs some investigation around whether browsers act this way for 0x0 SVGs and rasters.
155+
156+
Note: Replaced elements use different layout rules than normal elements.
157+
(In effect, it becomes equivalent to an HTML <{img}> element.)
158+
159+
Note: Replaced elements do not have ''::before'' or ''::after'' pseudo-elements;
160+
the 'content' property replaces their entire contents.
161+
123162
<dt><dfn type><<content-list>></dfn>
124163
<dd>
125-
[ <<string>> | contents | <<uri>> | <<quote>> | ''document-url'' | <<target>> | ''leader()'' ]+
164+
Equal to:
165+
166+
<pre class=prod>
167+
[ <<string>> | contents | <<image>> | <<quote>> | ''document-url'' | <<target>> | ''leader()'' ]+
168+
</pre>
169+
170+
Replaces the element's contents with oen or more anonymous inline boxes
171+
corresponding to the specified values,
172+
in the order specified.
173+
Its normal contents are suppressed
174+
and do not generate boxes,
175+
as if they were ''display: none''.
176+
177+
Each value contributes an inline box to the element's contents.
178+
For <<image>>, this is an inline anonymous replaced element;
179+
for the others, it's an anonymous inline run of text.
180+
181+
If an <<image>> represents an <a>invalid image</a>,
182+
the user agent must do one of the following:
126183

127-
See sections below for details on each of these.
184+
* "Skip" the <<image>>, generating nothing for it.
185+
* Display some indication that the image can't be displayed in place of the <<image>>,
186+
such as a "broken image" icon.
187+
188+
This specification intentionally does not define which behavior a user agent must use,
189+
but it must use one or the other consistently.
190+
191+
Note: If the value of <<content-list>> is a single <<image>>,
192+
it must instead be interpreted as a <<content-replacement>>.
193+
194+
<dt><dfn>/ <<string>></dfn>
195+
<dd>
196+
Specifies the "alt text" for the element.
197+
See [[#alt]] for details.
198+
If omitted,
199+
the element has no "alt text".
128200
</dl>
129201

130202
Issue: Should the contents keyword be replaced with ''content()''?
131203

132-
<p id="replaced">
133-
If the computed value of the part of the 'content' property that ends up being used is a single URI,
134-
then the element or pseudo-element is a replaced element.
135-
The box model defines different rules for the layout of replaced elements than normal elements.
136-
Replaced elements do not have '::before' and '::after' pseudo-elements;
137-
the 'content' property in the case of replaced content replaces the entire contents of the element's box.
138-
139204
<h3 id="accessibility">
140205
Accessibility of Generated Content</h3>
141206

@@ -188,9 +253,10 @@ Alternative Text for Speech</h3>
188253
<!--end copy from CSS-PSEUDO-->
189254

190255
<h2 id="content-values">
191-
Content Values and Functions</h2>
256+
<<content-list>> Values and Functions</h2>
192257

193-
The 'content' property can be used to add many different types of content to a document,
258+
The <<content-list>> value is used in 'content'
259+
to fill an element with one or more anonymous inline boxes,
194260
including images, strings, the values of counters, and the text value of elements.
195261
In this section we enumerate the possibilities.
196262

@@ -201,65 +267,36 @@ String</h3>
201267
<dl dfn-for="content, <content-list>" dfn-type=value>
202268
<dt><dfn><<string>></dfn>
203269
<dd>
204-
The element or pseudo-element contains the specified string.
205-
Occurrences of <a>white space</a> characters in the string
206-
are handled according to the properties given in the [[CSS3TEXT]] module.
207-
270+
Represents an anonymous inline box filled with the specified text.
271+
272+
Note: <a>White space</a> in the string is handled the same as in literal text,
273+
and controlled by the properties in [[CSS-TEXT-3]] and elsewhere.
274+
In particular, <a>white space</a> character can collapse,
275+
even across multiple strings,
276+
such as in ''content: "First " " Second";'',
277+
which by default will render similar to <code>"First Second"</code>
278+
(with a single visible space between the two words).
208279
</dl>
209280

210281
<h3 id="content-uri">
211-
URI</h3>
282+
<<image>></h3>
212283

213-
<dl dfn-type=value dfn-for=content>
214-
<dt><<uri>></dt>
284+
<dl dfn-type=value dfn-for="<content-list>">
285+
<dt><dfn><<image>></dfn></dt>
215286
<dd>
216-
For URIs other than URIs in the last comma separated section of the value,
217-
if the URI is available and the format is supported,
218-
then the element or pseudo-element becomes a replaced element,
219-
otherwise, the next item in the comma separated list is used, if any.
220-
</dl>
221-
222-
<div class="example">
223-
<pre>
224-
h1 { content: url(header/mng), url(header/png), none; }
225-
</pre>
226-
</div>
227-
228-
In the example above,
229-
if <code>header/mng</code> wasn't in a supported format,
230-
then <code>header/png</code> would have been used instead.
231-
In the example above, if <code>header/png</code> wasn't available either,
232-
then the <code>&lt;h1&gt;</code> element would be empty,
233-
as the last alternative is ''content/none''.
234-
235-
To make an element fallback on its contents, you have to explicitly give ''content/contents'' as a fallback:
236-
237-
<div class="example">
238-
<pre>content: url(1), url(2), url(3), contents;</pre>
239-
</div>
240-
241-
Issue: What happens when no formats are supported,
242-
and the author does not explicitly indicate a fallback?
243-
Why doesn't an element fallback to ''content/contents'' unless an author explicitly says so?
244-
245-
If the URI is part of the last comma separated value in the list, as the second URI in the following example:
246-
247-
<div class="example">
248-
<pre>h1 { content: url(welcome), "Welcome to: " url(logo); }</pre>
249-
</div>
250-
251-
...then if the file is available and the format is supported,
252-
then an anonymous replaced inline element is inserted,
253-
otherwise the image is ignored (as if it hadn't been given at all).
287+
Represents an anonymous inline replaced element
288+
filled with the specified <<image>>.
254289

255-
Issue: There appears to be some change from [[CSS21]] which says,
256-
"If the user agent cannot display the resource
257-
it must either leave it out as if it were not specified
258-
or display some indication that the resource cannot be displayed."
259-
Are we now saying that a user agent cannot display a missing image graphic in this situation?
290+
If the <<image>> represents an <a>invalid image</a>,
291+
this value instead represents nothing.
292+
(No inline content is added to the element,
293+
as if this value were "skipped".)
294+
</dl>
260295

261-
When a URI is used as replaced content,
262-
it <a href="#replaced">affects the generation</a> of ''::before'' and ''::after'' pseudo-elements.
296+
Issue: CSS2.1 explicitly allowed the UA to substitute a broken image icon
297+
if the image was invalid.
298+
However, no browser appears to do this.
299+
Is this removal okay?
263300

264301

265302
<h3 id="element-content">
@@ -947,8 +984,8 @@ The string-set property</h4>
947984
</div>
948985

949986

950-
<h4 id="string-function">The ''string()'' function
951-
</h4>
987+
<h4 id="string-function">
988+
The ''string()'' function</h4>
952989

953990
<pre class="prod">
954991
<dfn>string()</dfn> = string( <<custom-ident>> , [ first | start | last | first-except ]? )

0 commit comments

Comments
 (0)