You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:CSS Grid Critters 9.3底部网格项对齐问题解决方法

Fixing Bottom Row Alignment in CSS Grid Critters 9.3

Let's break down what's causing your bottom row alignment issue and fix it without messing up the top row:

First, let's look at your current grid setup:

  • You're using grid-template-rows: 50% auto which can behave unpredictably if the planet container doesn't have an explicit height—50% of an undefined height won't allocate space as you expect.
  • justify-items: end applies right-alignment to all grid items by default, which is likely why your bottom row elements aren't sitting where you want them.

Solution: Target Bottom Row Elements with justify-self

Instead of modifying the global justify-items or breaking the top row by styling dunes/water directly, override the alignment only for the bottom row items using justify-self—this lets you keep the top row's alignment intact while fixing the bottom:

planet {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: 1fr auto; /* Swap 50% for 1fr to let the top row fill available space reliably */
  justify-content: space-evenly;
  justify-items: end; /* Keep top row aligned to the end */
  align-content: space-between;
  height: 100%; /* Ensure the grid container has a defined height for row calculations */
}

/* Override alignment only for bottom row elements */
dunes, water {
  justify-self: start; /* Adjust to center/end based on the challenge's requirements */
}

Why This Works:

  • 1fr in grid-template-rows lets the top row take up all remaining space in the container, while auto makes the bottom row fit its content perfectly—this is more flexible than a fixed 50% for dynamic layouts.
  • Adding height: 100% to planet gives the grid a clear reference point to calculate row heights correctly.
  • justify-self targets individual grid items, so you can align the bottom row elements without disrupting the top row's end alignment.

If You Need to Keep the 50% Top Row Height:

If the challenge explicitly requires a 50% height for the top row, make sure the planet container has a fixed or explicit height (e.g., height: 200px or height: 100vh). Then keep the justify-self override for dunes/water to fix the bottom row alignment.


内容的提问来源于stack exchange,提问作者Dani Amsalem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 09:02:06