Bug 16856 - consider using division for negative flexibility
consider using division for negative flexibility
Status: RESOLVED FIXED
Product: CSS
Classification: Unclassified
Component: Flexbox
unspecified
PC Windows NT
: P1 normal
: ---
Assigned To: Tab Atkins Jr.
public-css-bugzilla
http://lists.w3.org/Archives/Public/w...
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-04-25 15:39 UTC by Alex Mogilevsky
Modified: 2012-06-07 20:11 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Mogilevsky 2012-04-25 15:39:43 UTC
(see email thread)

Currently, flexibility is always addition and subtraction, not multiplication or division. It makes sense when stretching - when items already have the space they wanted, they get equal share of additional space (given same flexibility).

But when shrinking, subtraction isn't really a good way of fair distribution. It works OK with minor adjustments, but if space shortage is significant and some items are much bigger than others, small items quickly shrink to zero (or their min size), while big fat items may not even notice. The problem can be mitigated by giving bigger items bigger negative flex, but it is only possible if the author knows what will be bigger...

Shrinking should be done by *dividing* the flexible lengths proportional to flexibility. Something like this:

	shrink-factor = sum(preferred-size / negative-flex) / available-space
	used-main-size = main-size / (shrink-factor * negative-flex)

this way, when shrinking, flex items remain proportional to their preferred size.
Comment 1 Alex Mogilevsky 2012-05-08 01:52:33 UTC
correct formula for the desired result is this:

space-shortage = sum(flex-basis) - available-space
shrink-factor = space-shortage / sum(flex-basis * negative-flex))
main-size = flex-basis * (1 - shrink-factor * negative-flex))

(previous proposed formula immediately scales all items by their negative flex and gets divizion by zero when negative-flex is zero)
Comment 2 Tab Atkins Jr. 2012-06-07 20:11:02 UTC
Done.