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

展开Accordion菜单时页面滚动异常求助

解决Accordion展开后页面无法滚动至顶部的问题

问题根源

你的.pageWrapper设置了height: 100vh,容器高度被固定为当前视口高度,当Accordion展开后内容超出视口时,容器不会自动延伸,导致溢出的内容无法通过页面滚动正常访问;同时align-items: center的垂直居中设置,会让溢出的顶部内容直接超出视口上边界,无法滚动查看。

修复方案

修改.pageWrapper的CSS样式:

  1. 把固定高度height: 100vh替换为最小高度min-height: 100vh,确保容器能随内容自动扩展
  2. 移除align-items: center,通过给内容添加上下自动外边距实现垂直居中,避免内容溢出时顶部被截断

修改后的CSS代码:

@import url('https://fonts.googleapis.com/css2?family=Open+Sans&family=Poppins&display=swap');
body {
  background-color: #1a2942;
  margin: 0; /* 可选:移除默认body外边距,避免滚动条异常 */
}

.pageWrapper {
  min-height: 100vh; /* 替换原height:100vh */
  display: flex;
  justify-content: center;
  /* 移除align-items: center */
  font-family: "Open Sans";
  flex-direction: column;
  padding: 20px 0; /* 可选:添加上下内边距,避免内容贴边 */
}

.heading {
  color: #fff;
  letter-spacing: 2px;
  text-align: center;
  font-size: 24px;
  margin-bottom: 30px;
  padding: 0px 15px;
  margin-top: auto; /* 添加自动上边距 */
}

.accordion {
  max-width: 600px;
  width: calc(100% - 20px);
  margin-bottom: auto; /* 添加自动下边距 */
}

details {
  background-color: #162237;
  border-radius: 5px;
  margin-bottom: 10px;
  filter: drop-shadow(1px 1px 2px #0d1521);
  border: 2px solid rgba(0, 0, 0, 0);
}

details:hover {
  border: 2px solid #ffffff;
}

details>summary {
  color: #fff;
  padding: 5px 10px;
  font-size: 18px;
}

details>p {
  padding: 5px 10px 10px 20px;
  color: #fff;
  font-size: 14px;
}

.main {
  text-indent: 16px;
}

效果说明

修改后,当Accordion展开内容超出视口时,.pageWrapper会自动扩展高度,页面能正常滚动查看全部内容,同时保持内容在视口内时的垂直居中效果。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 22:14:58