Bug 242313

Summary: margin-bottom wraps into next column if columns are of uneven height
Product: WebKit Reporter: Kimberly Grey <kimberly.grey>
Component: Layout and RenderingAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: ahmad.saleem792, bfulgham, karlcow, oliver.byford, simon.fraser, webkit-bug-importer, zalan
Priority: P2 Keywords: BrowserCompat, InRadar
Version: Safari 15   
Hardware: All   
OS: All   
URL: https://codepen.io/querkmachine/pen/ExEVVBL
Attachments:
Description Flags
HTML example (duplicate of Codepen)
none
Screenshot of issue in Safari 15.5
none
Test reduction none

Description Kimberly Grey 2022-07-04 06:09:07 PDT
Created attachment 460652 [details]
HTML example (duplicate of Codepen)

## Steps to reproduce

1. Open the Codepen at https://codepen.io/querkmachine/pen/ExEVVBL or the attached HTML file in Safari. 
2. Ensure the viewport is wide enough for the content to be presented in two columns without text wrapping.

## Expected behaviour

List items 1 to 7 appear in the first column, list items 8 to 13 appear in the second column. 

The tops of both columns are vertically aligned with one another. 

## Actual behaviour 

List items 1 to 7 appear in the first column, list items 8 to 13 appear in the second column.

The top of the second column appears 20 pixels below the top of the first column, as the `margin-bottom` from list item 7 is being rendered above list item 8. 

In this example, the issue is triggered by a combination of an odd number of list items and the last list item having the bottom margin reset to 0, creating a large enough difference in column lengths for the margin to wrap.

I could also reproduce this in the Safari 16 beta. The columns appear as expected in Firefox and Chromium browsers. 

## Potentially related bugs

- https://bugs.webkit.org/show_bug.cgi?id=17887
- https://bugs.webkit.org/show_bug.cgi?id=105411 
- https://bugs.webkit.org/show_bug.cgi?id=212505
Comment 1 Kimberly Grey 2022-07-04 06:10:53 PDT
Created attachment 460653 [details]
Screenshot of issue in Safari 15.5
Comment 2 Radar WebKit Bug Importer 2022-07-11 01:56:34 PDT
<rdar://problem/96815456>
Comment 3 Karl Dubost 2022-07-11 23:47:20 PDT
Usually adding an outline on elements has no influence on the layout as they do not participate to the computation of width and so on. 

But I forked the codepen of Kimberley and added outline for the list items.

and surprise, "it made it work"
https://codepen.io/webcompat/pen/rNdMBvK

As a note, do not use the technique to align the items, because this would have consequences for accessibility.
Comment 4 zalan 2022-07-12 07:39:55 PDT
Created attachment 460810 [details]
Test reduction

It looks like our multicol code gets confused when collapsing margins across columns.
Comment 5 Ahmad Saleem 2023-05-11 13:07:43 PDT
(In reply to zalan from comment #4)
> Created attachment 460810 [details]
> Test reduction
> 
> It looks like our multicol code gets confused when collapsing margins across
> columns.

Something similar to this?

https://chromium.googlesource.com/chromium/src.git/+/506506eac78a8106c4e92866a59b8c724ddc8b88