导航菜单和页脚不固定

我试图确保我的导航栏和页脚保持固定我已将两个位置设置为固定,并尝试设置导航栏的顶部:0和页脚的底部:0,但我仍然没有得到想要的结果,我尝试操纵和调整div 安排使代码更清晰并使其正常工作,但仍然没有得到预期的结果。请帮助我。

HTML代码

<html>


<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <meta http-equiv="X-UA-Compatible" content="ie=edge">

  <title>Archers</title>

  <link rel="stylesheet" href="arch.css">

</head>


<body>

<section id="main">

    <div class="parentDiv " >

      <div class="  contentDiv>

      <div id=" menu">

        <div id="navbar">

          <nav>

            <ul class="ul-style ">

              <li><a href="#portfolio">OUR PORTFOLIO</a></li>

              <li><a href="#process">OUR PROCESS</a></li>

              <li><a href="#about">ABOUT</a></li>

              <li><a href="#main">HOME</a></li>

            </ul>

          </nav>

        </div>

      </div>

      <div class="mainbg boxshadow"></div>

    </div>

</section>


  <section id="about" >

    <div class="parentDiv ">

<div class="  contentDiv>

        <a name=" #about"></a>

      </div>

      <div class="aboutbg boxshadow"></div>

    </div>

  </section>


  <section id=" process">

    <div class="parentDiv  ">

<div class="  contentDiv>

            <a name=" #process"></a>

      </div>

      <div class="processbg boxshadow"></div>

    </div>

  </section>

<section id=" portfolio">

    <div class="parentDiv ">

<div class="  contentDiv>

                  <a name=" #portfolio"></a>

      </div>

      <div class="portfoliobg boxshadow"></div>

    </div>

  </section>


  <footer>

    2020 DeborahPalmTree

  </footer>

  <script src="index.js" charset="utf-8"></script>

</body>

</html>```



***CSS CODE***


小怪兽爱吃肉
浏览 99回答 2
2回答

holdtom

您需要应用以下 css,因为您尚未为页脚分配任何 idfooter {&nbsp; &nbsp; position: fixed;&nbsp; &nbsp; bottom: 0;&nbsp; &nbsp; width: 100%;&nbsp; &nbsp; text-align: center;&nbsp; &nbsp; padding: 10px;&nbsp; &nbsp; background-color: #ddd;}如果您可以更改它,我建议您使用下面的 html 结构,因为这样您就可以更好地控制和设计样式<html><head>&nbsp; <meta charset="UTF-8">&nbsp; <meta name="viewport" content="width=device-width, initial-scale=1.0">&nbsp; <meta http-equiv="X-UA-Compatible" content="ie=edge">&nbsp; <title>Archers</title>&nbsp; <style>&nbsp;&nbsp;&nbsp; * {&nbsp; padding: 0;&nbsp; margin: 0;}body {&nbsp; width: 100%;&nbsp; height: 100%;}#navbar {&nbsp; width: 100%;&nbsp; height: calc (100% - 58px);&nbsp; background-color: rgba(219, 219, 219, 1.0);&nbsp; position: fixed;}ul li {&nbsp; list-style: none;&nbsp; float: right;&nbsp; margin: 20px;}li a {&nbsp; text-decoration: none;&nbsp; color: #ffffff;}.bg1 {&nbsp; background-color: rgba(219, 219, 219, 1.0);}.boxshadow {&nbsp; box-shadow: inset 0px 0px 0px 30px rgba(0,0,0,0.5);}.parentDiv {&nbsp; max-width: 100%;&nbsp; perspective: 500px;&nbsp; height: 100%;}.mainbg {&nbsp; width: 100%;&nbsp; height: 100vh;&nbsp; background-image: linear-gradient(rgba(245, 242, 242, 0.44), rgba(255,&nbsp; &nbsp; &nbsp; &nbsp; 255, 255, 0.5)), url('structural-images/img_house_trees.jpg');&nbsp; background-position: bottom;&nbsp; background-size: cover;&nbsp; background-repeat: no-repeat;}.aboutbg {&nbsp; width: 100%;&nbsp; height: 100vh;&nbsp; background-image: linear-gradient(rgba(219, 219, 219, 1.0), rgba(255,&nbsp; &nbsp; &nbsp; &nbsp; 255, 255, 0.5)),url('structural-images/img_construction_site.jpg');&nbsp; background-size: cover;&nbsp; background-position: bottom;&nbsp; background-repeat: no-repeat;}.processbg {&nbsp; width: 100%;&nbsp; height: 100vh;&nbsp; background-image: linear-gradient(rgba(219, 219, 219, 1.0), rgba(255,&nbsp; &nbsp; &nbsp; &nbsp; 255, 255, 0.5)),url('structural-images/img_arc_plan.jpg');&nbsp; background-size: cover;&nbsp; background-position: bottom;&nbsp; background-repeat: no-repeat;}.portfoliobg {&nbsp; width: 100%;&nbsp; height: 100vh;&nbsp; background-image: linear-gradient(rgba(219, 219, 219, 1.0), rgba(255,&nbsp; &nbsp; &nbsp; &nbsp; 255, 255, 0.5)),url('structural-images/img-structure-garden-car-park.jpg');&nbsp; background-size: cover;&nbsp; background-position: bottom;&nbsp; background-repeat: no-repeat;}#footer {&nbsp; position: fixed;&nbsp; height: 50px;&nbsp; width: 100%;&nbsp; background-color: rgba(219, 219, 219, 1.0);}footer {&nbsp; &nbsp; position: fixed;&nbsp; &nbsp; bottom: 0;&nbsp; &nbsp; width: 100%;&nbsp; &nbsp; text-align: center;&nbsp; &nbsp; padding: 10px;&nbsp; &nbsp; background-color: #ddd;}.main-body {&nbsp; &nbsp; margin: 58px 0 38px 0;}&nbsp;&nbsp;#navbar {&nbsp; &nbsp; width: 100%;&nbsp; &nbsp; background-color: rgb(221, 221, 221);&nbsp; &nbsp; position: fixed;&nbsp; &nbsp; top: 0;&nbsp; &nbsp; left: 0;&nbsp; &nbsp; z-index: 1;}&nbsp;&nbsp;&nbsp; </style></head><body contenteditable="false">&nbsp; &nbsp;<div id="navbar">&nbsp; &nbsp; &nbsp; <nav>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<ul class="ul-style ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li><a href="#portfolio">OUR PORTFOLIO</a></li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li><a href="#process">OUR PROCESS</a></li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li><a href="#about">ABOUT</a></li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li><a href="#main">HOME</a></li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</ul>&nbsp; &nbsp; &nbsp; </nav>&nbsp; &nbsp;</div>&nbsp; &nbsp;<div class="main-body">&nbsp; &nbsp; &nbsp; <section id="main">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<div class="parentDiv ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="&nbsp; contentDiv>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<div id=" menu"="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="mainbg boxshadow"></div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>&nbsp; &nbsp; &nbsp; </section>&nbsp; &nbsp; &nbsp; <section id="about">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<div class="parentDiv ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="&nbsp; contentDiv>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a name=" #about"="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="aboutbg boxshadow"></div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>&nbsp; &nbsp; &nbsp; </section>&nbsp; &nbsp; &nbsp; <section id=" process">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<div class="parentDiv&nbsp; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="&nbsp; contentDiv>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a name=" #process"="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="processbg boxshadow"></div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>&nbsp; &nbsp; &nbsp; </section>&nbsp; &nbsp; &nbsp; <section id="portfolio">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<div class="parentDiv ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="&nbsp; contentDiv>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a name=" #portfolio"="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="portfoliobg boxshadow"></div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>&nbsp; &nbsp; &nbsp; </section>&nbsp; &nbsp;</div>&nbsp; &nbsp;<footer>&nbsp; &nbsp; &nbsp; 2020 DeborahPalmTree&nbsp; &nbsp;</footer>&nbsp; &nbsp;<script src="index.js" charset="utf-8"></script></body></html>

守着星空守着你

请使用 z-index 和 Overflow 属性与您的固定项目。更新了CSS&nbsp; * {&nbsp; &nbsp; &nbsp; padding: 0;&nbsp; &nbsp; &nbsp; margin: 0;&nbsp; &nbsp; }&nbsp; &nbsp; body {&nbsp; &nbsp; &nbsp; width: 100%;&nbsp; &nbsp; &nbsp; height: 100%;&nbsp; &nbsp; }&nbsp; &nbsp; #navbar {&nbsp; &nbsp; &nbsp; width: 100%;&nbsp; &nbsp; &nbsp; height: calc (100% - 58px);&nbsp; &nbsp; &nbsp; background-color: rgba(219, 219, 219, 1.0);&nbsp; &nbsp; &nbsp; position: fixed;&nbsp; &nbsp; &nbsp; top:0px;&nbsp; &nbsp; &nbsp; left:0px;&nbsp; &nbsp; &nbsp; z-index:10;&nbsp; &nbsp; &nbsp; overflow:hidden;&nbsp; &nbsp; }&nbsp; &nbsp; ul li {&nbsp; &nbsp; &nbsp; list-style: none;&nbsp; &nbsp; &nbsp; float: right;&nbsp; &nbsp; &nbsp; margin: 20px;&nbsp; &nbsp; }&nbsp; &nbsp; li a {&nbsp; &nbsp; &nbsp; text-decoration: none;&nbsp; &nbsp; &nbsp; color: #ffffff;&nbsp; &nbsp; }&nbsp; &nbsp; .bg1 {&nbsp; &nbsp; &nbsp; background-color: rgba(219, 219, 219, 1.0);&nbsp; &nbsp; }&nbsp; &nbsp; .boxshadow {&nbsp; &nbsp; &nbsp; box-shadow: inset 0px 0px 0px 30px rgba(0,0,0,0.5);&nbsp; &nbsp; }&nbsp; &nbsp; .parentDiv {&nbsp; &nbsp; &nbsp; max-width: 100%;&nbsp; &nbsp; &nbsp; perspective: 500px;&nbsp; &nbsp; &nbsp; height: 100%;&nbsp; &nbsp; }&nbsp; &nbsp; .mainbg {&nbsp; &nbsp; &nbsp; width: 100%;&nbsp; &nbsp; &nbsp; height: 100vh;&nbsp; &nbsp; &nbsp; background-image: linear-gradient(rgba(245, 242, 242, 0.44), rgba(255,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 255, 255, 0.5)), url('structural-images/img_house_trees.jpg');&nbsp; &nbsp; &nbsp; background-position: bottom;&nbsp; &nbsp; &nbsp; background-size: cover;&nbsp; &nbsp; &nbsp; background-repeat: no-repeat;&nbsp; &nbsp; }&nbsp; &nbsp; .aboutbg {&nbsp; &nbsp; &nbsp; width: 100%;&nbsp; &nbsp; &nbsp; height: 100vh;&nbsp; &nbsp; &nbsp; background-image: linear-gradient(rgba(219, 219, 219, 1.0), rgba(255,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 255, 255, 0.5)),url('structural-images/img_construction_site.jpg');&nbsp; &nbsp; &nbsp; background-size: cover;&nbsp; &nbsp; &nbsp; background-position: bottom;&nbsp; &nbsp; &nbsp; background-repeat: no-repeat;&nbsp; &nbsp; }&nbsp; &nbsp; .processbg {&nbsp; &nbsp; &nbsp; width: 100%;&nbsp; &nbsp; &nbsp; height: 100vh;&nbsp; &nbsp; &nbsp; background-image: linear-gradient(rgba(219, 219, 219, 1.0), rgba(255,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 255, 255, 0.5)),url('structural-images/img_arc_plan.jpg');&nbsp; &nbsp; &nbsp; background-size: cover;&nbsp; &nbsp; &nbsp; background-position: bottom;&nbsp; &nbsp; &nbsp; background-repeat: no-repeat;&nbsp; &nbsp; }&nbsp; &nbsp; .portfoliobg {&nbsp; &nbsp; &nbsp; width: 100%;&nbsp; &nbsp; &nbsp; height: 100vh;&nbsp; &nbsp; &nbsp; background-image: linear-gradient(rgba(219, 219, 219, 1.0), rgba(255,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 255, 255, 0.5)),url('structural-images/img-structure-garden-car-park.jpg');&nbsp; &nbsp; &nbsp; background-size: cover;&nbsp; &nbsp; &nbsp; background-position: bottom;&nbsp; &nbsp; &nbsp; background-repeat: no-repeat;&nbsp; &nbsp; }&nbsp; &nbsp; #footer {&nbsp; &nbsp; &nbsp; position: fixed;&nbsp; &nbsp; &nbsp; height: 50px;&nbsp; &nbsp; &nbsp; width: 100%;&nbsp; &nbsp; &nbsp; background-color: rgba(219, 219, 219, 1.0);bottom:0px;left:0px;z-index:10;overflow:hidden;&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5