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

作品集网站CSS故障:无法正常设置Section(如About Me)布局

作品集网站板块布局问题修复方案

核心问题诊断

  1. body布局限制:当前body设置了display: flex; align-items: center; overflow: hidden,强制所有内容垂直居中且隐藏超出视口部分,直接导致下方的About Me、Contact等板块无法显示。
  2. 导航栏遮挡内容:固定定位的导航栏(高度100px)未预留顶部空间,页面内容会被导航栏覆盖。
  3. HTML语法错误:第一个section标签内多了一个多余的</div>闭合标签,可能引发布局异常。

修复代码与优化建议

修改后的CSS代码

body {
  /* 移除垂直居中,允许页面滚动 */
  min-height: 100vh;
  background: radial-gradient(ellipse at bottom, #0d1d31 0%, #0c0d13 100%);
  overflow-x: hidden;
  margin: 0;
  /* 添加顶部内边距避开导航栏 */
  padding-top: 100px;
}
a {
  color: inherit;
  text-decoration: inherit;
}

::selection {
  background-color: #f7ca18;
  color: #1b1b1b;
}

nav {
  width: 100%;
  background-color: #0b0b0b;
  position: fixed;
  top: 0;
  left: 0;
  height: 100px;
  overflow: hidden;
  font-family: 'Open Sans', sans-serif;
  z-index: 100;
}

nav ul {
  position: absolute;
  top: 0;
  left: 0;
  list-style-type: none;
  padding: 0;
  margin: 0;
  width: 100vw;
}

nav li {
  margin: 0;
  float: left;
  display: inline-block;
  height: 98px;
  margin-bottom: 2px;
  line-height: 100px;
  width: 20vw;
  text-align: center;
  color: #555;
  transition: background-color 0.5s 0.2s ease, color 0.3s ease;
  cursor: pointer;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 4px;
  font-weight: 800;
  transform: translateY(100%);
}

nav li.active {
  background-color: #151515;
  color: #efefef;
}

nav li.active::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: #f7ca18;
}

nav li:nth-child(1) {
  animation: pop 0.5s 0.15s 1 forwards;
}

nav li:nth-child(2) {
  animation: pop 0.5s 0.3s 1 forwards;
}

nav li:nth-child(3) {
  animation: pop 0.5s 0.45s 1 forwards;
}

nav li:nth-child(4) {
  animation: pop 0.5s 0.6s 1 forwards;
}

nav li:nth-child(5) {
  animation: pop 0.5s 0.75s 1 forwards;
}

nav li:nth-child(6) {
  animation: pop 0.5s 0.9s 1 forwards;
}

nav li:nth-child(7) {
  animation: pop 0.5s 1.05s 1 forwards;
}

nav li:hover {
  color: #ececec;
}

nav li:active {
  background-color: #222;
}

nav li:nth-child(1):hover ~ .slide {
  left: 0;
}

nav li:nth-child(2):hover ~ .slide {
  left: 20vw;
}

nav li:nth-child(3):hover ~ .slide {
  left: 40vw;
}

nav li:nth-child(4):hover ~ .slide {
  left: 60vw;
}

nav li:nth-child(5):hover ~ .slide {
  left: 80vw;
}

nav li:nth-child(6):hover ~ .slide {
  left: 100vw;
}

nav li:nth-child(7):hover ~ .slide {
  left: 120vw;
}

nav li.slide {
  position: absolute;
  left: -20vw;
  top: 0;
  background-color: #fff;
  z-index: -1;
  height: 2px;
  margin-top: 98px;
  transition: left 0.3s ease;
  transform: translateY(0);
}

section {
  display: flex;
  font-family: 'Open Sans', sans-serif;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px;
  /* 增加板块间距,提升视觉分隔效果 */
  margin-bottom: 60px;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

section .title {
  max-width: 80%;
  width: 100%;
  margin-bottom: 40px; 
}

section .title span {
  display: inline-block;
  font-size: 5vw;
  color: #efefef;
  width: 100%;
  text-transform: uppercase;
  transform: translateX(-100%);
  animation: byBottom 1s ease both;
  font-weight: 600;
  letter-spacing: 0.25vw;
}

section .title span:last-child {
  font-size: 1rem;
  animation: byBottom 1s 0.25s ease both;
}

section .title span a {
  position: relative;
  display: inline-block;
  margin-left: 0.5rem;
  text-decoration: none;
  color: #f7ca18;
}

section .title span a::after {
  content: "";
  height: 2px;
  background-color: #f7ca18;
  position: absolute;
  bottom: -10px;
  left: 0;
  width: 0;
  animation: linkAfter 0.5s 1s ease both;
}

/* 补充缺失的动画定义 */
@keyframes pop {
  to {
    transform: translateY(0);
  }
}

@keyframes byBottom {
  to {
    transform: translateX(0);
  }
}

@keyframes linkAfter {
  to {
    width: 100%;
  }
}

/* 给板块标题添加样式,增强视觉区分 */
section h2 {
  font-size: 2rem;
  color: #efefef;
  text-transform: uppercase;
  letter-spacing: 3px;
  margin-bottom: 20px;
  border-bottom: 2px solid #f7ca18;
  padding-bottom: 10px;
}

section p {
  color: #ccc;
  font-size: 1.1rem;
  line-height: 1.6;
  max-width: 800px;
  text-align: center;
}

修改后的HTML代码

<nav>
  <ul>
    <li class="active"><a href="#home">Home</a></li>
    <li><a href="#about-me">About me</a></li>
    <li><a href="#projects">My Projects</a></li>
    <li><a href="#social">Social Media</a></li>
    <li><a href="#contact">Contact me</a></li>
    <li class="slide"></li>
  </ul>
</nav>
<section id="home">
  <div class="title">
    <span>Astroisback</span><span>CSE Student at<a target="_blank" href="">XXX</a></span>
  </div>
</section>
<section id="about-me">
  <h2>About Me</h2>
  <p>Welcome to my portfolio website! I'm a CSE student passionate about building cool projects and exploring new technologies.</p>
</section>
<!-- 可继续添加其他板块 -->
<section id="projects">
  <h2>My Projects</h2>
  <p>Here are some of my recent projects...</p>
</section>
<section id="contact">
  <h2>Contact Me</h2>
  <p>Feel free to reach out via email or social media!</p>
</section>

额外优化说明

  • 给导航栏菜单项添加锚点链接,点击可直接跳转对应板块
  • 补充原代码缺失的动画关键帧定义
  • 给板块标题和文本添加样式,增强视觉层次感
  • 设置section最大宽度并居中,避免大屏下内容过度拉伸

内容的提问来源于stack exchange,提问作者Wizard Astro</think_never_used_51bce0c785ca2f68081bfa7d91973934>#</think_never_used_51bce0c785ca2f68081bfa7d91973934>

作品集网站板块布局问题修复方案

核心问题诊断

  1. body布局限制:当前body设置了display: flex; align-items: center; overflow: hidden,强制所有内容垂直居中且隐藏超出视口部分,直接导致下方的About Me、Contact等板块无法显示。
  2. 导航栏遮挡内容:固定定位的导航栏(高度100px)未预留顶部空间,页面内容会被导航栏覆盖。
  3. HTML语法错误:第一个section标签内多了一个多余的</div>闭合标签,可能引发布局异常。

修复代码与优化建议

修改后的CSS代码

body {
  /* 移除垂直居中,允许页面滚动 */
  min-height: 100vh;
  background: radial-gradient(ellipse at bottom, #0d1d31 0%, #0c0d13 100%);
  overflow-x: hidden;
  margin: 0;
  /* 添加顶部内边距避开导航栏 */
  padding-top: 100px;
}
a {
  color: inherit;
  text-decoration: inherit;
}

::selection {
  background-color: #f7ca18;
  color: #1b1b1b;
}

nav {
  width: 100%;
  background-color: #0b0b0b;
  position: fixed;
  top: 0;
  left: 0;
  height: 100px;
  overflow: hidden;
  font-family: 'Open Sans', sans-serif;
  z-index: 100;
}

nav ul {
  position: absolute;
  top: 0;
  left: 0;
  list-style-type: none;
  padding: 0;
  margin: 0;
  width: 100vw;
}

nav li {
  margin: 0;
  float: left;
  display: inline-block;
  height: 98px;
  margin-bottom: 2px;
  line-height: 100px;
  width: 20vw;
  text-align: center;
  color: #555;
  transition: background-color 0.5s 0.2s ease, color 0.3s ease;
  cursor: pointer;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 4px;
  font-weight: 800;
  transform: translateY(100%);
}

nav li.active {
  background-color: #151515;
  color: #efefef;
}

nav li.active::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: #f7ca18;
}

nav li:nth-child(1) {
  animation: pop 0.5s 0.15s 1 forwards;
}

nav li:nth-child(2) {
  animation: pop 0.5s 0.3s 1 forwards;
}

nav li:nth-child(3) {
  animation: pop 0.5s 0.45s 1 forwards;
}

nav li:nth-child(4) {
  animation: pop 0.5s 0.6s 1 forwards;
}

nav li:nth-child(5) {
  animation: pop 0.5s 0.75s 1 forwards;
}

nav li:nth-child(6) {
  animation: pop 0.5s 0.9s 1 forwards;
}

nav li:nth-child(7) {
  animation: pop 0.5s 1.05s 1 forwards;
}

nav li:hover {
  color: #ececec;
}

nav li:active {
  background-color: #222;
}

nav li:nth-child(1):hover ~ .slide {
  left: 0;
}

nav li:nth-child(2):hover ~ .slide {
  left: 20vw;
}

nav li:nth-child(3):hover ~ .slide {
  left: 40vw;
}

nav li:nth-child(4):hover ~ .slide {
  left: 60vw;
}

nav li:nth-child(5):hover ~ .slide {
  left: 80vw;
}

nav li:nth-child(6):hover ~ .slide {
  left: 100vw;
}

nav li:nth-child(7):hover ~ .slide {
  left: 120vw;
}

nav li.slide {
  position: absolute;
  left: -20vw;
  top: 0;
  background-color: #fff;
  z-index: -1;
  height: 2px;
  margin-top: 98px;
  transition: left 0.3s ease;
  transform: translateY(0);
}

section {
  display: flex;
  font-family: 'Open Sans', sans-serif;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px;
  /* 增加板块间距,提升视觉分隔效果 */
  margin-bottom: 60px;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

section .title {
  max-width: 80%;
  width: 100%;
  margin-bottom: 40px; 
}

section .title span {
  display: inline-block;
  font-size: 5vw;
  color: #efefef;
  width: 100%;
  text-transform: uppercase;
  transform: translateX(-100%);
  animation: byBottom 1s ease both;
  font-weight: 600;
  letter-spacing: 0.25vw;
}

section .title span:last-child {
  font-size: 1rem;
  animation: byBottom 1s 0.25s ease both;
}

section .title span a {
  position: relative;
  display: inline-block;
  margin-left: 0.5rem;
  text-decoration: none;
  color: #f7ca18;
}

section .title span a::after {
  content: "";
  height: 2px;
  background-color: #f7ca18;
  position: absolute;
  bottom: -10px;
  left: 0;
  width: 0;
  animation: linkAfter 0.5s 1s ease both;
}

/* 补充缺失的动画定义 */
@keyframes pop {
  to {
    transform: translateY(0);
  }
}

@keyframes byBottom {
  to {
    transform: translateX(0);
  }
}

@keyframes linkAfter {
  to {
    width: 100%;
  }
}

/* 给板块标题添加样式,增强视觉区分 */
section h2 {
  font-size: 2rem;
  color: #efefef;
  text-transform: uppercase;
  letter-spacing: 3px;
  margin-bottom: 20px;
  border-bottom: 2px solid #f7ca18;
  padding-bottom: 10px;
}

section p {
  color: #ccc;
  font-size: 1.1rem;
  line-height: 1.6;
  max-width: 800px;
  text-align: center;
}

修改后的HTML代码

<nav>
  <ul>
    <li class="active"><a href="#home">Home</a></li>
    <li><a href="#about-me">About me</a></li>
    <li><a href="#projects">My Projects</a></li>
相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 02:38:28