Skip to content

Fix: honor break-before and break-after on floated elements - #2728

Merged
liZe merged 3 commits into
Kozea:mainfrom
danfitz36:fix/break-on-floats-2277
Jun 29, 2026
Merged

liZe merged 3 commits into
Kozea:mainfrom
danfitz36:fix/break-on-floats-2277

Conversation

@danfitz36

Copy link
Copy Markdown
Contributor

Summary

  • Floated elements bypassed break property handling because they are routed through _out_of_flow_layout instead of _in_flow_layout
  • Added forced page break detection for floats following the CSS Fragmentation spec: "User agents should also apply these properties to floated boxes whose containing block is in the normal flow of the root fragmented element."
  • Handles both break-before and break-after on floated elements

Test plan

  • Added test_float_break_after_page — verifies break-after: page on a float forces a page break
  • Added test_float_break_before_page — verifies break-before: page on a float forces a page break

Fixes #2277

danfitz36 and others added 3 commits April 4, 2026 18:53
Floated elements bypassed break property handling because they are
routed through _out_of_flow_layout instead of _in_flow_layout. Add
forced page break detection for floats following the CSS Fragmentation
spec: "User agents should also apply these properties to floated boxes
whose containing block is in the normal flow of the root fragmented
element."

Fixes Kozea#2277

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@liZe

liZe commented Jun 29, 2026

Copy link
Copy Markdown
Member

Hi!

Thanks for this pull request, here’s a short review.

  • As we want to check breaks between blocks, there’s no need to check before and after each block: checking once is enough, as we do for in-flow blocks.
  • Forced or prevented breaks are determined using the break-after of the first block and the break-before of the second block, with a possible combination. We never rely on only one value, as you did with break-after.
  • Your second check is done before breaking or aborting the float rendering. It’s wrong if the float is split between two pages, as we don’t want to honor break-after value if the end of the float is not rendered.
  • Your first check is the same as the one done for in-flow blocks. Instead of duplicating the code, it’s possible to move it at the beginning of the child layout instead.
  • As we want to break between floats, the find_last_in_flow_child function is not adapted to find the previous block that creates a class A break. We have to find the last child that is either an in-flow block or a float.

I updated your code to fix these issues, and added more tests.

@liZe liZe added the feature New feature that should be supported label Jun 29, 2026
@liZe liZe added this to the 70.0 milestone Jun 29, 2026
@liZe liZe added bug Existing features not working as expected and removed feature New feature that should be supported labels Jun 29, 2026
@liZe
liZe merged commit 409b41e into Kozea:main Jun 29, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Existing features not working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Page breaks are not honored on floating elements

2 participants