diff --git a/weasyprint/formatting_structure/boxes.py b/weasyprint/formatting_structure/boxes.py index 3031e0cfd..548e6be3d 100644 --- a/weasyprint/formatting_structure/boxes.py +++ b/weasyprint/formatting_structure/boxes.py @@ -313,8 +313,6 @@ def is_monolithic(self): def establishes_formatting_context(self): """Return whether this box establishes a block formatting context.""" # See https://www.w3.org/TR/CSS2/visuren.html#block-formatting - # TODO: columns shouldn't be block boxes, this condition would then be - # useless when this is fixed return ( self.is_floated() or self.is_absolutely_positioned() or diff --git a/weasyprint/layout/block.py b/weasyprint/layout/block.py index 0bec3e428..8cc2a87e3 100644 --- a/weasyprint/layout/block.py +++ b/weasyprint/layout/block.py @@ -124,8 +124,11 @@ def block_box_layout(context, box, bottom_space, skip_stack, result = block_container_layout( context, box, bottom_space, skip_stack, page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins, discard, max_lines) - new_box = result[0] - if new_box and new_box.is_table_wrapper: + # TODO: columns shouldn't be block boxes, this condition would then be + # useless when this is fixed. + if not (new_box := result[0]) or new_box.is_column: + return result + if new_box.is_table_wrapper or new_box.establishes_formatting_context(): # Don't collide with floats # https://www.w3.org/TR/CSS21/visuren.html#floats position_x, position_y, _ = avoid_collisions( diff --git a/weasyprint/layout/float.py b/weasyprint/layout/float.py index 2a5bf8205..94369db74 100644 --- a/weasyprint/layout/float.py +++ b/weasyprint/layout/float.py @@ -195,12 +195,13 @@ def avoid_collisions(context, box, containing_block, outer=True): # - line boxes # - table wrappers # - block-level replaced box - # - element establishing new formatting contexts (not handled) + # - element establishing new formatting contexts assert ( (box.style['float'] in ('right', 'left')) or isinstance(box, boxes.LineBox) or box.is_table_wrapper or - isinstance(box, boxes.BlockReplacedBox)) + isinstance(box, boxes.BlockReplacedBox) or + box.establishes_formatting_context()) # The x-position of the box depends on its type. position_x = max_left_bound