Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vertical positioning for absolute replaced elements #1823

Merged
merged 2 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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