Skip to content

Commit

Permalink
Merge pull request #1823 from bot-jonas/fix1822
Browse files Browse the repository at this point in the history
Fix vertical positioning for absolute replaced elements
  • Loading branch information
liZe authored Feb 27, 2023
2 parents 404b32a + aa28d5c commit ec4c65e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion tests/layout/test_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,23 +327,30 @@ def test_absolute_positioning_8():
def test_absolute_images():
page, = render_pages('''
<style>
@page { size: 50px; }
img { display: block; position: absolute }
</style>
<div style="margin: 10px">
<img src=pattern.png />
<img src=pattern.png style="left: 15px" />
<img src=pattern.png style="top: 15px" />
<img src=pattern.png style="bottom: 25px" />
</div>
''')
html, = page.children
body, = html.children
div, = body.children
img1, img2 = div.children
img1, img2, img3, img4 = div.children
assert div.height == 0
assert (div.position_x, div.position_y) == (0, 0)
assert (img1.position_x, img1.position_y) == (10, 10)
assert (img1.width, img1.height) == (4, 4)
assert (img2.position_x, img2.position_y) == (15, 10)
assert (img2.width, img2.height) == (4, 4)
assert (img3.position_x, img3.position_y) == (10, 15)
assert (img3.width, img3.height) == (4, 4)
assert (img4.position_x, img4.position_y) == (10, 21) # (50 - 4) - 25
assert (img4.width, img4.height) == (4, 4)

# TODO: test the various cases in absolute_replaced()

Expand Down
4 changes: 2 additions & 2 deletions weasyprint/layout/absolute.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ def absolute_replaced(context, box, cb_x, cb_y, cb_width, cb_height):
box.margin_bottom = 0
remaining = cb_height - box.margin_height()
if box.top == 'auto':
box.top = remaining
box.top = remaining - box.bottom
if box.bottom == 'auto':
box.bottom = remaining
box.bottom = remaining - box.top
elif 'auto' in (box.margin_top, box.margin_bottom):
remaining = cb_height - (box.border_height() + box.top + box.bottom)
if box.margin_top == box.margin_bottom == 'auto':
Expand Down

0 comments on commit ec4c65e

Please sign in to comment.