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

Grid+Flex布局下图片适配及左侧多滚动列表布局问题求助

Dashboard布局问题解决方案

一、左右等宽全屏布局与右侧图片适配

  1. 基础全屏两栏布局实现:
    • 给body设置display: grid; grid-template-columns: 1fr 1fr; height: 100vh; margin: 0;,直接实现左右等宽、占满浏览器窗口的两栏结构,无需额外复杂嵌套。
  2. 右侧幻灯片图片适配修复:
    • <right-panel>设置width: 100%; height: 100%; display: flex; justify-content: center; align-items: center;,通过flex实现图片容器的居中对齐。
    • <picture-box>内的图片标签设置max-width: 100%; max-height: 100%; object-fit: contain;,object-fit: contain会保证图片按原始比例缩放,且完全适配容器空间,不会超出面板边界。

示例代码片段:

body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 100vh;
  margin: 0;
}

right-panel {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f5f5f5; /* 可选:用于调试布局 */
}

picture-box img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

二、左侧底部并排滚动列表重叠修复

移除left-panel-bottom-content的position: absolute属性,改用grid实现并排布局:

  1. 给<left-panel-bottom>设置display: grid; grid-template-columns: 1fr 1fr; gap: 16px; height: 100%;,gap用于控制两个列表的间距。
  2. 每个滚动列表容器设置overflow-y: auto;,确保内容过多时可纵向滚动。
  3. 若左侧面板为垂直flex布局,给<left-panel-bottom>设置flex: 1;,让它占满左侧面板的剩余空间,保证列表有足够高度。

示例代码片段:

left-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

left-panel-bottom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  flex: 1;
  padding: 10px;
}

.scroll-list {
  overflow-y: auto;
  border: 1px solid #eee; /* 可选:用于区分列表边界 */
  border-radius: 4px;
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 03:57:06