@@ -830,6 +830,20 @@ Placement Precision: the 'item-tolerance' property</h3>
830830 see <a href='https://github.com/w3c/csswg-drafts/issues/3071'>discussions</a>
831831 on how that might work.
832832
833+ <h3 id="masonry-dense-packing">
834+ Dense Placement: the ''item-pack/dense'' keyword</h3>
835+
836+ In [=grid layout=] , ''grid-auto-flow: dense'' allows backtracking
837+ during the [[css-grid-2#auto-placement-algo|grid item placement algorithm]] .
838+ The ''item-pack/dense'' keyword similarly allows backtracking
839+ during the [[#masonry-layout-algorithm|masonry placement algorithm]] .
840+ However, because masonry placement and sizing are intertwined,
841+ an item can only backtrack into a compatible empty slot if
842+ the total used size of that slot’s tracks
843+ matches the used size of the item’s normal-placement tracks.
844+
845+ Note: This restriction avoids laying out the item more than once.
846+
833847<h3 id="masonry-layout-algorithm">
834848Masonry Layout and Placement Algorithm</h3>
835849
@@ -873,6 +887,18 @@ Masonry Layout and Placement Algorithm</h3>
873887 and then layout the item.
874888 Set the [=running position=] of the spanned [=grid axis=] tracks
875889 to <code><var> max_pos</var> + [=outer size=] + 'grid-gap' </code> .
890+
891+ <li>
892+ If the [=masonry container=] uses ''item-pack/dense'' packing,
893+ and there exists skipped empty space (e.g. due to spanning items)
894+ in the layout into which the item, as it is sized now,
895+ could have fit without impacting other items’ placement
896+ if it were earlier in the placement order,
897+ and the tracks it would have spanned at that point
898+ have the same total used size as the tracks into which it is currently placed,
899+ move the item into the earliest such position
900+ and rewind the [=auto-placement cursor=] and the [=running position=]
901+ to their values before this item’s placement.
876902 </ol>
877903
878904 Note: This algorithm chooses the track
@@ -1510,6 +1536,8 @@ Recent Changes</h3>
15101536 <a href="https://github.com/w3c/csswg-drafts/issues/12111">Issue 12111</a> )
15111537 * Added a placeholder for a [=masonry layout=] 'display' value.
15121538 (<a href="https://github.com/w3c/csswg-drafts/issues/12022">Issue 12022</a> )
1539+ * Defined [[#masonry-dense-packing|dense packing]] for [=masonry layout=] .
1540+ (<a href="https://github.com/w3c/csswg-drafts/issues/9326">Issue 9326</a> )
15131541 * Tweak baseline alignment to export the highest/lowest among the first/last items of every track.
15141542 (<a href="https://github.com/w3c/csswg-drafts/issues/9530">Issue 9530</a> )
15151543
0 commit comments