Re: [css-box] shrink-to-fit and floats

On Mon, Mar 7, 2016 at 4:41 PM, Pavel Panchekha <me@pavpanchekha.com> wrote:
>> If the div had "margin-right: -10px", all the above still applies, but
>> the calculation of the minimum width that doesn't trigger overflow
>> changes.  Overflow happens when the *margin box* of an element is
>> wider than its container, and in this case the margin box is 0px wide
>> - 10px from width, minus 10px from margin-right.
>
> Am I taking you correctly, then, that margins are treated differently
> when determining shrink-to-fit and ordinary width, namely that right
> margins are not ignored for computing shrink-to-fit width yet are
> ignored for computing ordinary width (in situations where that's
> applicable)?

You can think of it that way, sure.  It's probably more accurate to
say it's the "width of the containing block" that's treated
differently - it's not a definite value, so you can't actually resolve
the equation as stated (thus the "CSS 2.1 does not define the exact
algorithm" part).

> Every other part of the layout for this example you and I agree on.
>
> I suppose I can reduce my confusion now to this question:
> when is the margin-right ignored, and when is it not?
>
> It sounds like margin-right is ignored during the layout of block-level,
> non-replaced elements in flow, when computing their actual layout,
> but it is not ignored when computing their width for the purposes of
> determining the preferred [minimum] width of a container.

When you're *actually performing layout* as specified in CSS, you do
what CSS says.  That means, when things are overconstrained in
block-level layout, you ignore the right margin.

But the layout performed during "preferred width" calculations is not
actually specified in CSS2.1, so you can't read the algorithms too
literally.  For CSS2.1, you have to examine implementations to figure
out how things are actually done; we've since fixed things in the
Sizing spec to actually specify what happens (and nothing gets
"ignored" in that case, because we don't invoke the section 10.3.3
equality at all!).

>> Sizing spec does correct this lack and define things more precisely.
>
> That's a useful draft to be aware of, thank you. I think the relevant
> sentence of that specification would be this one, in ยง4.3:
>
>> Otherwise, if the computed inline-size of the block is fit-content, auto,
>> or fill, its min-content inline-size contribution is its min-content
>> inline size plus any inline-axis margin, border, and padding.
>
> Is this referring to the inline-axis (that is, the left & right) *used*
> values
> for margin, border, and padding or the *computed* values?
>
> The used values are the ones computed by ignoring the specified
> margin-right, while the computed values would be the expected ones.
> It may be best to amend that draft to make the choice here clearer.

You haven't *determined* the used values yet, because you're still in
the process of figuring out the ancestor's width.  Layout is an
iterative process that you have to perform in the correct order, down
to the leaves and then back up to the root.

~TJ

Received on Tuesday, 8 March 2016 00:50:33 UTC