You need to enable JavaScript to run this app. 页脚内两个p/div元素无法实现上下堆叠,其余区域同类布局正常
优惠活动
大模型
产品
解决方案
定价
更多

页脚内两个p/div元素无法实现上下堆叠,其余区域同类布局正常

enter image description here

我试过好几种调整方案:不再用p元素包裹页脚内容、把页脚文本改成无序列表项、将文本放进独立div容器,但始终没法做出预期效果——也就是让大号的“TestTest”标题下方堆叠小号的“test”文本。页面其他区域用独立div做这种上下堆叠布局都能正常生效,我现在根本找不到页脚区域布局失效的原因。

以下是我页面用到的HTML和CSS代码:

body {
  background-color: #414141;
  /* background: url(/images/background.jpg) no-repeat center center fixed;
  background-size: cover;
  resize: both;
  overflow: scroll;
  overflow-x: hidden; */
  margin: 0;
  padding: 0;
}
::-webkit-scrollbar {
  width: 0px;
  font-family: Arial;
}

@font-face {
  font-family: ubuntu-medium;
  src: url(/fonts/ubuntu-medium.ttf);
}

@media (max-width: 7680px) {
  body {
    background: url(/images/background.jpg) no-repeat center center fixed;
    background-size: cover;
    resize: both;
    overflow: scroll;
    overflow-x: hidden;
  }
}

@media (max-width: 800px) {
  body {
    background: url(/images/mobilebackground.jpg) no-repeat center center fixed;
  }
}

#NavSection {
  margin-top: 3%;
}

#MainNav {
  position: left;
  margin-left: 11%;
}

#Menu li {
  font-family: ubuntu-medium;
  font-weight: normal;
  color: #414141;
  padding: 0px 10px;
  display: inline;
  font-size: 15px;
  list-style-type: none;
}

#Menu a:hover {
  text-decoration-color: #414141;
  text-underline-offset: 0.12em;
  text-decoration-line: underline;
  text-decoration-style: solid;
  text-decoration-thickness: 4px;
  box-shadow: 0px 13px 4px -3px rgba(65, 65, 65, 0.616);
}

hr {
  margin: 0px;
  border: 2px solid red;
  width: auto;
}

a {
  color: #414141;
  text-decoration: none;
}

a:active {
  color: #ff0000;
}

#SiteTitle {
  margin-left: 0.5%;
}

#TestTest {
  font-family: Impact;
  font-weight: normal;
  font-size: 30px;
  color: #ffffff;
  text-decoration: underline;
  text-decoration-color: #414141;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.08em;
}

#Japan {
  color: red;
}

ul {
  list-style-type: none;
  margin-top: 0px;
  margin-bottom: 0px;
  padding: 0px;
}

#SecondNav {
  float: right;
  font-family: ubuntu-medium;
  font-weight: normal;
  color: #414141;
  padding: 0px 10px;
  font-size: 15px;
  margin-right: 11%;
}

#SecondMenu a:hover {
  text-decoration: overline 4px solid #414141;
  box-shadow: 0px -13px 4px -3px rgba(65, 65, 65, 0.616);
}

#SecondMenu li {
  margin-bottom: 5px;
  font-family: ubuntu-medium;
  font-weight: normal;
  color: #414141;
  padding: 0px 10px;
  display: inline;
  font-size: 15px;
  list-style-type: none;
}

#ContentDiv {
  width: 70%;
  height: 40%;
  position: absolute;
  top: 30%;
  left: 15%;
  transform: translateX(0%);
  background-color: rgba(255, 0, 0, 0.4);
}

#ContentSection {
  width: 90%;
  height: 70%;
  position: absolute;
  top: 15%;
  left: 5%;
  background-color: rgba(255, 255, 255, 0.9);
}

#Content {
  margin: 3%;
}

footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 7%;
  background-color: #414141;
  font-family: Impact;
  font-weight: normal;
  font-size: 20px;
  color: #ffffff;
}

#FooterTitle {
  float: right;
  margin: 0.5%;
}
#FooterJapan {
  color: #ff0000;
}
#FooterCaption {
  font-size: x-small;
  float: right;
  margin: 0.5%;
  font-family: ubuntu-medium;
  font-weight: normal;
}
<!DOCTYPE html>
<html>
  <head>
    <title>Test</title>
    <link rel="stylesheet" href="stylesheet.css" type="text/css" />
  </head>

  <body>
    
    <div id="NavSection">
      <div id="TopNav">
        <nav id="MainNav">
          <ul id="Menu">
            <li><a href="">Home</a></li>
            <li><a href="">About</a></li>
            <li><a href="">Contact</a></li>
          </ul>
        </nav>
      </div>

      <hr />

      <div id="SecondNavSection">
        <nav id="SecondNav">
          <ul id="SecondMenu">
            <li><a href="">Archives</a></li>
            <li><a href="">Categories</a></li>
          </ul>
        </nav>
      </div>

      <div id="SiteTitle">
        <h1 id="TestTest">Test<span id="Japan">Test</span></h1>
      </div>
    </div>

    <div id="ContentDiv">
      <main id="ContentSection">
        <div id="Content">
          <p>Content goes here.</p>
        </div>
      </main>
    </div>

    <footer>
      <p id="FooterTitle">Test <span id="FooterJapan">Test</span></p>
      <p id="FooterCaption">Test</p>
    </footer>

  </body>

</html>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.11.02 06:27:02