diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/percentage-min-height-with-containing-block-padding.txt b/Tests/LibWeb/Layout/expected/block-and-inline/percentage-min-height-with-containing-block-padding.txt
new file mode 100644
index 0000000000..3b499c4c21
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/block-and-inline/percentage-min-height-with-containing-block-padding.txt
@@ -0,0 +1,9 @@
+Viewport <#document> at (0,0) content-size 800x600 children: not-inline
+ BlockContainer at (0,0) content-size 800x616 [BFC] children: not-inline
+ BlockContainer
at (8,8) content-size 784x600 children: not-inline
+ BlockContainer at (8,108) content-size 784x500 children: not-inline
+ BlockContainer at (18,118) content-size 764x250 children: inline
+ line 0 width: 36.84375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+ frag 0 from TextNode start: 0, length: 5, rect: [18,118 36.84375x17.46875]
+ "hello"
+ TextNode <#text>
diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/percentage-min-height.txt b/Tests/LibWeb/Layout/expected/block-and-inline/percentage-min-height.txt
new file mode 100644
index 0000000000..2cc77576d3
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/block-and-inline/percentage-min-height.txt
@@ -0,0 +1,8 @@
+Viewport <#document> at (0,0) content-size 800x600 children: not-inline
+ BlockContainer at (0,0) content-size 800x53.46875 [BFC] children: not-inline
+ BlockContainer at (8,8) content-size 784x37.46875 children: not-inline
+ BlockContainer at (18,18) content-size 764x17.46875 children: inline
+ line 0 width: 36.84375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+ frag 0 from TextNode start: 0, length: 5, rect: [18,18 36.84375x17.46875]
+ "hello"
+ TextNode <#text>
diff --git a/Tests/LibWeb/Layout/input/block-and-inline/percentage-min-height-with-containing-block-padding.html b/Tests/LibWeb/Layout/input/block-and-inline/percentage-min-height-with-containing-block-padding.html
new file mode 100644
index 0000000000..b2636bdb2c
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/block-and-inline/percentage-min-height-with-containing-block-padding.html
@@ -0,0 +1,13 @@
+
+
\ No newline at end of file
diff --git a/Tests/LibWeb/Layout/input/block-and-inline/percentage-min-height.html b/Tests/LibWeb/Layout/input/block-and-inline/percentage-min-height.html
new file mode 100644
index 0000000000..21253f289f
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/block-and-inline/percentage-min-height.html
@@ -0,0 +1,8 @@
+
+hello
\ No newline at end of file
diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
index b78238d22d..f8db4dcc1f 100644
--- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
@@ -1390,9 +1390,16 @@ CSS::Length FormattingContext::calculate_inner_width(Layout::Box const& box, Ava
return width.resolved(box, width_of_containing_block_as_length_for_resolve);
}
-CSS::Length FormattingContext::calculate_inner_height(Layout::Box const& box, AvailableSize const& available_height, CSS::Size const& height) const
+CSS::Length FormattingContext::calculate_inner_height(Layout::Box const& box, AvailableSize const&, CSS::Size const& height) const
{
- auto height_of_containing_block = available_height.to_px();
+ auto const* containing_block = box.non_anonymous_containing_block();
+ auto const& containing_block_state = m_state.get(*containing_block);
+ auto height_of_containing_block = containing_block_state.content_height();
+ if (box.computed_values().position() == CSS::Position::Absolute) {
+ // https://www.w3.org/TR/css-position-3/#def-cb
+ // If the box has position: absolute, then the containing block is formed by the padding edge of the ancestor
+ height_of_containing_block += containing_block_state.padding_top + containing_block_state.padding_bottom;
+ }
auto height_of_containing_block_as_length_for_resolve = CSS::Length::make_px(height_of_containing_block);
if (height.is_auto()) {
return height.resolved(box, height_of_containing_block_as_length_for_resolve);