Parking Attendant — CSS

Park cars in the right slots with position: 24 levels of static, relative, absolute and sticky. The most visual CSS position game around.

What you learn in this game

position: relative shifts an element from its original spot without changing the layout of other elements. The element still "remembers" where it came from.

position: absolute pulls the element out of the normal flow and positions it relative to the nearest ancestor that has a position (other than static). If there is none, the element is positioned relative to the viewport.

When a parent has position: relative, a child with position: absolute is positioned relative to that parent, not the viewport. This is a very common pattern in CSS.

z-index controls the stacking order of overlapping elements. An element with a higher z-index appears above one with a lower z-index. z-index only works on elements that have a position other than static.

position: fixed positions an element relative to the viewport (the browser window). The element stays put even when the page is scrolled. Commonly used for navbars or floating buttons.

position: sticky is a mix of relative and fixed. The element behaves like relative until a certain scroll threshold, then "sticks" like fixed. It must have at least one offset (top, bottom, etc.).

What the levels ask

  1. The green minibus stopped in the queue. Move it 50px to the right, into its bay, with position: relative and left.
  2. Mr. Dodi's blue motorbike stopped too high. Bring it down 40px into its bay with position: relative and top.
  3. The blue minibus has to move 60px right and 30px down at once: position: relative with left and top.
  4. The pedicab overshot. Back it up 40px to the left and 20px up: a negative value moves the other way.
  5. The red motorbike parks in the lot's top left corner. Use position: absolute, then measure from the corner with top and left.
  6. The blue motorbike goes to the lot's bottom right corner. Use position: absolute and measure from the right and bottom sides.
  7. The green minibus goes to the bay at top: 60px and left: 100px from the lot's corner, with position: absolute.
  8. Ms. Wulan's orange motorbike goes to the bay at top: 80px and left: 120px, with position: absolute.
  9. .parkiran is already position: relative, so the lot's corner is the point to measure from. Park the blue minibus absolutely at top: 20px, left: 20px.
  10. Bagas's bicycle at top: 10px; left: 10px, the blue minibus at top: 10px; right: 10px. Both absolute inside the lot.
  11. Three at once: red motorbike top: 10px; left: 10px, blue motorbike top: 80px; left: 130px, pedicab bottom: 10px; right: 10px.
  12. The pedicab at top: 50px; left: 80px, the orange motorbike at top: 120px; left: 180px.

And more, 24 levels in all.