Skip to content

Commit 1b24ad9

Browse files
committed
Include padding in outer size of item elements
1 parent 2606a2b commit 1b24ad9

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

tests/layout/test_flex.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,3 +1784,34 @@ def test_flex_direction_column_next_page():
17841784
assert article.children[0].children[0].children[0].position_y == 0
17851785
assert article.children[1].children[0].children[0].text == 'C'
17861786
assert article.children[1].children[0].children[0].position_y == 2
1787+
1788+
1789+
@assert_no_logs
1790+
def test_flex_1_item_padding():
1791+
page, = render_pages('''
1792+
<article style="display: flex; width: 100px; font: 2px weasyprint">
1793+
<div>abc</div>
1794+
<div style="flex: 1; padding-right: 5em">def</div>
1795+
</article>
1796+
''')
1797+
html, = page.children
1798+
body, = html.children
1799+
article, = body.children
1800+
div1, div2 = article.children
1801+
assert div1.border_width() + div2.border_width() == article.width
1802+
1803+
1804+
@assert_no_logs
1805+
def test_flex_1_item_padding_direction_column():
1806+
page, = render_pages('''
1807+
<article style="display: flex; flex-direction: column; height: 100px;
1808+
font: 2px weasyprint">
1809+
<div>abc</div>
1810+
<div style="flex: 1; padding-top: 5em">def</div>
1811+
</article>
1812+
''')
1813+
html, = page.children
1814+
body, = html.children
1815+
article, = body.children
1816+
div1, div2 = article.children
1817+
assert div1.border_height() + div2.border_height() == article.height

weasyprint/layout/flex.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,16 @@ def flex_layout(context, box, bottom_space, skip_stack, containing_block, page_i
221221
child.flex_base_size = flex_basis
222222
if main == 'width':
223223
child.main_outer_extra = (
224-
child.border_left_width + child.border_right_width)
224+
child.border_left_width + child.border_right_width +
225+
child.padding_left + child.padding_right)
225226
if child.margin_left != 'auto':
226227
child.main_outer_extra += child.margin_left
227228
if child.margin_right != 'auto':
228229
child.main_outer_extra += child.margin_right
229230
else:
230231
child.main_outer_extra = (
231-
child.border_top_width + child.border_bottom_width)
232+
child.border_top_width + child.border_bottom_width +
233+
child.padding_top + child.padding_bottom)
232234
if child.margin_top != 'auto':
233235
child.main_outer_extra += child.margin_top
234236
if child.margin_bottom != 'auto':

0 commit comments

Comments
 (0)