diff --git a/Base/res/html/misc/nth-child.html b/Base/res/html/misc/nth-child.html
index 5413202a09..11865fde4b 100644
--- a/Base/res/html/misc/nth-child.html
+++ b/Base/res/html/misc/nth-child.html
@@ -52,6 +52,9 @@
.acid3 > div:nth-child(-5n+3) {
background-color: lightblue;
}
+ .test-of-type > div:nth-child(2n of div) {
+ background-color: lightblue;
+ }
.test-of > div:nth-child(3n+1 of .special) {
background-color: lightblue;
}
@@ -191,6 +194,22 @@
15
+:nth-child(2n of div)
+
+
1
+
Paragraph
+
2 +
+
Paragraph
+
3
+
Paragraph
+
4 +
+
Paragraph
+
5
+
Paragraph
+
6 +
+
Paragraph
+
+
:nth-child(3n+1 of .special)
1 +
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index 87c5108fad..f44d53a120 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -4491,12 +4491,14 @@ Optional
Parser::parse_a_n_plus_b_patt
if (is_n_dimension(first_value)) {
a = first_value.token().dimension_value_int();
- values.skip_whitespace();
- auto& second_value = values.next_token();
- if (second_value.is(Token::Type::EndOfFile)) {
+ if (!values.has_next_token() || values.peek_token().is(Token::Type::Whitespace)) {
//
return make_return_value();
- } else if (is_signed_integer(second_value)) {
+ }
+
+ values.skip_whitespace();
+ auto& second_value = values.next_token();
+ if (is_signed_integer(second_value)) {
//
b = second_value.token().to_integer();
return make_return_value();
@@ -4552,12 +4554,14 @@ Optional Parser::parse_a_n_plus_b_patt
// -n ['+' | '-']
if (is_dashn(first_value)) {
a = -1;
- values.skip_whitespace();
- auto& second_value = values.next_token();
- if (second_value.is(Token::Type::EndOfFile)) {
+ if (!values.has_next_token() || values.peek_token().is(Token::Type::Whitespace)) {
// -n
return make_return_value();
- } else if (is_signed_integer(second_value)) {
+ }
+
+ values.skip_whitespace();
+ auto& second_value = values.next_token();
+ if (is_signed_integer(second_value)) {
// -n
b = second_value.token().to_integer();
return make_return_value();
@@ -4605,12 +4609,14 @@ Optional Parser::parse_a_n_plus_b_patt
// '+'?† n ['+' | '-']
if (is_n(first_after_plus)) {
a = 1;
- values.skip_whitespace();
- auto& second_value = values.next_token();
- if (second_value.is(Token::Type::EndOfFile)) {
+ if (!values.has_next_token() || values.peek_token().is(Token::Type::Whitespace)) {
// '+'?† n
return make_return_value();
- } else if (is_signed_integer(second_value)) {
+ }
+
+ values.skip_whitespace();
+ auto& second_value = values.next_token();
+ if (is_signed_integer(second_value)) {
// '+'?† n
b = second_value.token().to_integer();
return make_return_value();