Skip to content

Commit

Permalink
Merge pull request #2135 from xavidotron/percent
Browse files Browse the repository at this point in the history
Allow column-direction flex containers to use percentage-based heights.
  • Loading branch information
liZe authored Apr 26, 2024
2 parents df7c9b9 + c4f3f7b commit 5a74e3b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 18 additions & 0 deletions tests/layout/test_flex.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,21 @@ def test_flex_absolute():
<div style="display: flex; position: absolute">
<div>a</div>
</div>''')


@assert_no_logs
def test_flex_percent_height():
page, = render_pages('''
<style>
.a { height: 10px; width: 10px; }
.b { height: 10%; width: 100%; display: flex; flex-direction: column; }
</style>
<div class="a"">
<div class="b"></div>
</div>''')
html, = page.children
body, = html.children
a, = body.children
b, = a.children
assert a.height == 10
assert b.height == 1
5 changes: 4 additions & 1 deletion weasyprint/layout/flex.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ def flex_layout(context, box, bottom_space, skip_stack, containing_block,
block.block_level_width(box, containing_block)
else:
if box.style['height'] != 'auto':
box.height = box.style['height'].value
if box.style['height'].unit == '%':
box.height = box.style['height'].value / 100. * containing_block.height
else:
box.height = box.style['height'].value
else:
box.height = 0
for i, child in enumerate(children):
Expand Down

0 comments on commit 5a74e3b

Please sign in to comment.