Bug 242313 - margin-bottom wraps into next column if columns are of uneven height
Summary: margin-bottom wraps into next column if columns are of uneven height
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: Safari 15
Hardware: All All
: P2 Normal
Assignee: Nobody
URL: https://codepen.io/querkmachine/pen/E...
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2022-07-04 06:09 PDT by Kimberly Grey
Modified: 2023-05-11 13:07 PDT (History)
7 users (show)

See Also:


Attachments
HTML example (duplicate of Codepen) (830 bytes, text/html)
2022-07-04 06:09 PDT, Kimberly Grey
no flags Details
Screenshot of issue in Safari 15.5 (45.89 KB, image/png)
2022-07-04 06:10 PDT, Kimberly Grey
no flags Details
Test reduction (278 bytes, text/html)
2022-07-12 07:39 PDT, zalan
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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