Skip to content

Commit 727d9c1

Browse files
authored
[css-sizing-3][css-ui-4] Box sizing migration
* Add more guidance on usage of ambiguous sizing terms * Port box-sizing example from css-ui-3/4 to css-sizing-3 * Add caniuse bikeshed ref for box-sizing in css-sizing-3 * Drop box-sizing from css-ui-4 in favor of css-sizing-3 Closes #2458
1 parent 7507d61 commit 727d9c1

File tree

2 files changed

+64
-193
lines changed

2 files changed

+64
-193
lines changed

css-sizing-3/Overview.bs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ Module interactions</h3>
5353
<p>This module extends the 'width', 'height', 'min-width', 'min-height', 'max-width', 'max-height', and 'column-width'
5454
features defined in [[!CSS2]] chapter 10 and in [[!CSS3COL]]
5555

56+
<p>The definition of the 'box-sizing' property in module supersedes the one in [[CSS-UI-3]].
57+
5658
<h3 id="values">
5759
Values</h3>
5860

@@ -508,7 +510,7 @@ Containing or Excluding Floats</h4>
508510
████████ ███████ ██ ██ ██████ ████ ████████ ████ ██ ██ ██████
509511
-->
510512

511-
<h3 id="box-sizing">
513+
<h3 id="box-sizing" caniuse="css3-boxsizing">
512514
Box Edges for Sizing: the 'box-sizing' property</h3>
513515

514516

@@ -620,22 +622,67 @@ Box Edges for Sizing: the 'box-sizing' property</h3>
620622
</pre>
621623
</div>
622624

625+
<div class="example">
626+
This example uses box-sizing to evenly horizontally split
627+
two divs with fixed size borders inside a div container,
628+
which would otherwise require additional markup.
629+
630+
sample CSS:
631+
<pre><code class="lang-css">
632+
div.container {
633+
width:38em;
634+
border:1em solid black;
635+
}
636+
637+
div.split {
638+
box-sizing:border-box;
639+
width:50%;
640+
border:1em silver ridge;
641+
float:left;
642+
}
643+
</code></pre>
644+
645+
sample HTML fragment:
646+
<pre><code class="lang-markup">
647+
&lt;div class="container"&gt;
648+
&lt;div class="split"&gt;This div occupies the left half.&lt;/div&gt;
649+
&lt;div class="split"&gt;This div occupies the right half.&lt;/div&gt;
650+
&lt;/div&gt;
651+
</code></pre>
652+
653+
demonstration of sample CSS and HTML:
654+
<div style="max-width:38em; border:1em solid black"><div style="box-sizing:border-box; width:50%; border:1em silver ridge; float:left">This div should occupy the left half.</div><div style="box-sizing:border-box; width:50%; border:1em silver ridge; float:left">This div should occupy the right half.</div>The two divs above should appear side by side, each (including borders) 50% of the content width of their container. If instead they are stacked one on top of the other then your browser does not support 'box-sizing'.</div>
655+
</div>
656+
623657
Note: Certain HTML elements,
624658
such as <{button}>,
625659
default to ''border-box'' behavior.
626660
See HTML for details on which elements have this behavior.
627661

628-
In the CSS specifications,
662+
In legacy CSS specifications,
629663
the terms <a>width</a>, <a>height</a>,
630664
<a lt="min width">minimum (min) width</a>,
631665
<a lt="min height">minimum (min) height</a>,
632666
<a lt="max width">maximum (max) width</a>, and
633667
<a lt="max height">maximum (max) height</a>
634-
refer to the <a lt="inner size">inner</a> size
668+
generally refer to the <a lt="inner size">inner</a> size
635669
(<a lt="content box">content-box</a> size)
636670
of a <a>box</a>
637671
unless otherwise indicated.
638672

673+
Refer to [[CSS-UI-3#box-sizing]] for an explicit disambiguation of these terms
674+
for the <a href="https://www.w3.org/TR/CSS21/visudet.html">Visual formatting model details</a> section of [[CSS2]].
675+
676+
<div class=advisement>To avoid ambiguities,
677+
specification authors should avoid ambiguous uses of terms such as width or height without further qualification,
678+
and should explicitely refer and link to
679+
the <a lt="inner size">inner</a> size,
680+
the <a lt="outer size">outer</a> size,
681+
the size of the <a href="https://www.w3.org/TR/css2/box.html#box-dimensions">border-box</a>,
682+
the <a>computed value</a> of the <a>sizing properties</a>,
683+
etc,
684+
as appropriate for each case.
685+
</div>
639686

640687
<!--
641688
██████ ███████ ██ ██ ██ ██ ██ ██ ██

css-ui-4/Overview.bs

Lines changed: 14 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -140,196 +140,20 @@ which itself replaced and superseded the following:
140140
<a href="https://www.w3.org/TR/2000/WD-css3-userint-20000216">User Interface for CSS3 (16 February 2000)</a> [[CSS-UI-3]]
141141
</ul>
142142

143-
144-
<h2 id="box-model">Box Model addition</h2>
145-
146-
<h3 id="box-sizing" caniuse="css3-boxsizing">Changing the Box Model: the 'box-sizing' property</h3>
147-
148-
<pre class="propdef">
149-
Name: box-sizing
150-
Value: content-box | border-box
151-
Initial: content-box
152-
Applies to: all elements that accept width or height
153-
Inherited: no
154-
Percentages: N/A
155-
Media: visual
156-
Computed value: specified value
157-
</pre>
158-
159-
<dl dfn-type=value dfn-for=box-sizing>
160-
<dt><dfn>content-box</dfn>
161-
<dd>
162-
This is the behavior of width and height as specified by CSS2.1.
163-
The specified width and height (and respective min/max properties)
164-
apply to the width and height respectively of the content box of the element.
165-
The padding and border of the element are laid out
166-
and drawn outside the specified width and height.
167-
168-
<dt><dfn>border-box</dfn>
169-
<dd>
170-
Length and percentages values for width and height (and respective min/max properties)
171-
on this element determine the border box of the element.
172-
That is, any padding or border specified on the element
173-
is laid out and drawn inside this specified width and height.
174-
The content width and height are calculated
175-
by subtracting the border and padding widths of the respective sides
176-
from the specified 'width'
177-
and 'height' properties.
178-
As the content width and height
179-
<a href="https://www.w3.org/TR/CSS21/visudet.html#the-width-property">cannot be negative</a> ([[!CSS21]], section 10.2),
180-
this computation is floored at 0.
181-
Used values, as exposed for instance through getComputedStyle(), also refer to the border box.
182-
183-
Note: This is the behavior of width and height as commonly implemented
184-
by legacy HTML user agents for replaced elements and input elements.
185-
</dl>
186-
187-
Note: In contrast to the length and percentage values,
188-
the ''width/auto'' value of the 'width' and 'height' properties
189-
(as well as other keyword values introduced by later specifications,
190-
unless otherwise specified)
191-
is not influenced by the 'box-sizing' property,
192-
and always sets the size of the content box.
193-
194-
The following terms, whose definitions vary based on the computed value of 'box-sizing' are introduced:
195-
196-
<table border="1">
197-
<tr>
198-
<th>
199-
<th>''box-sizing: content-box''
200-
<th>''box-sizing: border-box''
201-
202-
<tr>
203-
<td><dfn>min inner width</dfn>
204-
<td>'min-width'
205-
<td>max(0, 'min-width' &minus; 'padding-left' &minus; 'padding-right' &minus; 'border-left-width' &minus; 'border-right-width')
206-
207-
<tr>
208-
<td><dfn>max inner width</dfn>
209-
<td>'max-width'
210-
<td>max(0, 'max-width' &minus; 'padding-left' &minus; 'padding-right' &minus; 'border-left-width' &minus; 'border-right-width')
211-
212-
<tr>
213-
<td><dfn>min inner height</dfn>
214-
<td>'min-height'
215-
<td>max(0, 'min-height' &minus; 'padding-top' &minus; 'padding-bottom' &minus; 'border-top-width' &minus; 'border-bottom-width')
216-
217-
<tr>
218-
<td><dfn>max inner height</dfn>
219-
<td>'max-height'
220-
<td>max(0, 'max-height' &minus; 'padding-top' &minus; 'padding-bottom' &minus; 'border-top-width' &minus; 'border-bottom-width')
221-
</table>
222-
223-
The <a href="https://www.w3.org/TR/CSS21/visudet.html">Visual formatting model details</a> of [[!CSS21]] are written assuming ''box-sizing: content-box''. The following disambiguations are made to clarify the behavior for all values of 'box-sizing':
224-
225-
<ol>
226-
<li>
227-
In <a href="https://www.w3.org/TR/CSS21/visudet.html#blockwidth">10.3.3</a>,
228-
the second <q>width</q> in the following phrase is to be interpreted as <a spec="css21">content width</a>:
229-
<q>If 'width' is not ''width/auto'' and 'border-left-width' + 'padding-left' + 'width' + [...]</q>
230-
231-
<li>
232-
In <a href="https://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-width">10.3.7</a>,
233-
<q>width</q> is to be interpreted as <a spec="css21">content width</a> in the following equation:
234-
<q>'left' + 'margin-left' + 'border-left-width' + 'padding-left' + 'width' + [...]</q>
235-
236-
<li>
237-
In <a href="https://www.w3.org/TR/CSS21/visudet.html#min-max-widths">10.4</a>,
238-
<q>width</q>, <q>height</q>, <q>min-width</q>, <q>max-width</q>, <q>min-height</q> and <q>max-height</q>
239-
are respectively to be interpreted as
240-
<a spec="css21">content width</a>, <a spec="css21">content height</a>, <a>min inner width</a>, <a>max inner width</a>, <a>min inner height</a> and <a>max inner height</a> in the following phrases:
241-
242-
<ol>
243-
<li>
244-
<q>The tentative used width is calculated [...]</q>
245-
246-
<li>
247-
<q>If the tentative used width is greater than 'max-width',
248-
the rules above are applied again,
249-
but this time using the computed value of 'max-width' as the computed value for 'width'.</q>
250-
251-
<li>
252-
<q>If the resulting width is smaller than 'min-width',
253-
the rules above are applied again,
254-
but this time using the value of 'min-width' as the computed value for 'width'.</q>
255-
256-
<li>
257-
<q>Select from the table the resolved height and width values for the appropriate constraint violation.
258-
Take the max-width and max-height as max(min, max) so that min ≤ max holds true.
259-
In this table w and h stand for the results of the width and height computations [...]</q>
260-
261-
<li>
262-
All instances of these words in the table
263-
264-
<li>
265-
<q>Then apply the rules under "Calculating widths and margins" above, as if 'width' were computed as this value.</q>
266-
</ol>
267-
268-
<li>
269-
In <a href="https://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-height">10.6.4</a>,
270-
<q>height</q> is to be interpreted as <a spec="css21">content height</a> in the following equation:
271-
<q>'top' + 'margin-top' + 'border-top-width' + 'padding-top' + 'height' + [...]</q>
272-
273-
<li>
274-
In <a href="https://www.w3.org/TR/CSS21/visudet.html#min-max-heights">10.7</a>,
275-
<q>width</q>, <q>height</q>, <q>min-height</q> and <q>max-height</q>
276-
are respectively to be interpreted as
277-
<a spec="css21">content width</a>, <a spec="css21">content height</a>, <a>min inner height</a> and <a>max inner height</a> in the following phrases:
278-
279-
<ol>
280-
<li>
281-
<q>The tentative used height is calculated [...]</q>
282-
283-
<li>
284-
<q>If this tentative height is greater than 'max-height',
285-
the rules above are applied again, but this time using the value of 'max-height' as the computed value for 'height'.</q>
286-
287-
<li>
288-
<q>If the resulting height is smaller than 'min-height',
289-
the rules above are applied again,
290-
but this time using the value of 'min-height' as the computed value for 'height'.</q>
291-
292-
<li>
293-
<q>[...] use the algorithm under Minimum and maximum widths above to find the used width and height.
294-
Then apply the rules under "Computing heights and margins" above,
295-
using the resulting width and height as if they were the computed values.</q>
296-
</ol>
297-
</ol>
298-
299-
<div class="example">
300-
<h4 id="box-sizing-example" class="no-num no-toc">Using box-sizing to evenly share space</h4>
301-
302-
This example uses box-sizing to evenly horizontally split
303-
two divs with fixed size borders inside a div container,
304-
which would otherwise require additional markup.
305-
306-
sample CSS:
307-
<pre><code class="lang-css">
308-
div.container {
309-
width:38em;
310-
border:1em solid black;
311-
}
312-
313-
div.split {
314-
box-sizing:border-box;
315-
width:50%;
316-
border:1em silver ridge;
317-
float:left;
318-
}
319-
</code></pre>
320-
321-
sample HTML fragment:
322-
<pre><code class="lang-markup">
323-
&lt;div class="container"&gt;
324-
&lt;div class="split"&gt;This div occupies the left half.&lt;/div&gt;
325-
&lt;div class="split"&gt;This div occupies the right half.&lt;/div&gt;
326-
&lt;/div&gt;
327-
</code></pre>
328-
329-
demonstration of sample CSS and HTML:
330-
<div style="width:38em; border:1em solid black"><div style="box-sizing:border-box; width:50%; border:1em silver ridge; float:left">This div should occupy the left half.</div><div style="box-sizing:border-box; width:50%; border:1em silver ridge; float:left">This div should occupy the right half.</div>The two divs above should appear side by side, each (including borders) 50% of the content width of their container. If instead they are stacked one on top of the other then your browser does not support 'box-sizing'.</div>
331-
</div>
332-
143+
Note:
144+
<span id="box-model"></span>
145+
<span id="box-sizing"></span>
146+
<span id="propdef-box-sizing"></span>
147+
<span id="valdef-box-sizing-content-box"></span>
148+
<span id="valdef-box-sizing-border-box"></span>
149+
<span id="min-inner-width"></span>
150+
<span id="max-inner-width"></span>
151+
<span id="min-inner-height"></span>
152+
<span id="max-inner-height"></span>
153+
<span id="example-d824f1dc"></span>
154+
<span id="box-sizing-example"></span>
155+
The 'box-sizing' property was previously defined in this section of the specification,
156+
but has been moved to [[CSS-SIZING-3#box-sizing]].
333157

334158
<h2 id="outline-props" caniuse="outline">Outline properties</h2>
335159

0 commit comments

Comments
 (0)