diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c
index 554cd42..5e157a4 100644
--- a/gtk/gtklistbox.c
+++ b/gtk/gtklistbox.c
@@ -18,6 +18,7 @@
 #include "config.h"
 
 #include "gtkadjustmentprivate.h"
+#include "gtkcssnodeprivate.h"
 #include "gtklistbox.h"
 #include "gtkwidget.h"
 #include "gtkmarshalers.h"
@@ -1166,6 +1167,25 @@ do_sort (GtkListBoxRow *a,
   return priv->sort_func (a, b, priv->sort_func_target);
 }
 
+static void
+gtk_list_box_css_node_foreach (gpointer data,
+                               gpointer user_data)
+{
+  GtkWidget **previous = user_data;
+  GtkWidget *row = data;
+  GtkCssNode *row_node;
+  GtkCssNode *prev_node;
+
+  if (*previous)
+    {
+      prev_node = gtk_widget_get_css_node (*previous);
+      row_node = gtk_widget_get_css_node (row);
+      gtk_css_node_set_after (row_node, prev_node);
+    }
+
+  *previous = row;
+}
+
 /**
  * gtk_list_box_invalidate_sort:
  * @box: a #GtkListBox
@@ -1180,11 +1200,15 @@ void
 gtk_list_box_invalidate_sort (GtkListBox *box)
 {
   GtkListBoxPrivate *priv = BOX_PRIV (box);
+  GtkWidget *previous = NULL;
 
   g_return_if_fail (GTK_IS_LIST_BOX (box));
 
   g_sequence_sort (priv->children, (GCompareDataFunc)do_sort, box);
 
+  g_sequence_foreach (priv->children, gtk_list_box_css_node_foreach, &previous);
+  gtk_css_node_invalidate (gtk_widget_get_css_node (GTK_WIDGET (box)), GTK_CSS_CHANGE_ANY_SELF);
+
   gtk_list_box_invalidate_headers (box);
   gtk_widget_queue_resize (GTK_WIDGET (box));
 }
@@ -2321,6 +2345,8 @@ gtk_list_box_remove (GtkContainer *container,
   if (row == priv->drag_highlighted_row)
     gtk_list_box_drag_unhighlight_row (box);
 
+  gtk_css_node_set_parent (gtk_widget_get_css_node (GTK_WIDGET (row)), NULL);
+
   next = gtk_list_box_get_next_visible (box, ROW_PRIV (row)->iter);
   gtk_widget_unparent (child);
   g_sequence_remove (ROW_PRIV (row)->iter);
@@ -2599,6 +2625,37 @@ gtk_list_box_prepend (GtkListBox *box,
   gtk_list_box_insert (box, child, 0);
 }
 
+static void
+gtk_list_box_apply_css_node (GtkListBox    *box,
+                             GtkWidget     *child,
+                             GSequenceIter *iter)
+{
+  GSequenceIter *sibling_iter;
+  GtkCssNode *child_node;
+  GtkCssNode *sibling_node;
+  GtkWidget *sibling;
+
+  child_node = gtk_widget_get_css_node (child);
+
+  sibling_iter = g_sequence_iter_prev (iter);
+  if (sibling_iter != iter)
+    {
+      sibling = g_sequence_get (sibling_iter);
+      sibling_node = gtk_widget_get_css_node (sibling);
+      gtk_css_node_set_after (child_node, sibling_node);
+      return;
+    }
+
+  sibling_iter = g_sequence_iter_next (iter);
+  if (!g_sequence_iter_is_end (sibling_iter))
+    {
+      sibling = g_sequence_get (sibling_iter);
+      sibling_node = gtk_widget_get_css_node (sibling);
+      gtk_css_node_set_before (child_node, sibling_node);
+      return;
+    }
+}
+
 /**
  * gtk_list_box_insert:
  * @box: a #GtkListBox
@@ -2650,6 +2707,8 @@ gtk_list_box_insert (GtkListBox *box,
       iter = g_sequence_insert_before (current_iter, row);
     }
 
+  gtk_list_box_apply_css_node (box, GTK_WIDGET (row), iter);
+
   ROW_PRIV (row)->iter = iter;
   gtk_widget_set_parent (GTK_WIDGET (row), GTK_WIDGET (box));
   gtk_widget_set_child_visible (GTK_WIDGET (row), TRUE);
