在Angular中让页脚始终位于底部

7

我正在尝试将页脚放在底部。

enter image description here

有些原因导致它呈现出这样的效果。

在index.html文件中,我有:

<main flex layout="column">
      <div>
        <div ui-view="" ></div>
      </div>
    </main>

    <footer>
      <md-toolbar class="md-hue-2 md-scroll-shrink">
        <div layout="row" layout-align="center center" flex>
          Powered by Webocity Technologies
        </div>
      </md-toolbar>

无论是否粘性,这看起来都不对。这里有什么问题,如何解决?
3个回答

18

使用 position:fixed;bottom:0px; 将您的页脚显示在页面底部。

footer{
position:fixed;
bottom:0px;
background-color:pink;
width:100%;
}
<main flex layout="column">
      <div>
        <div ui-view="" ></div>
      </div>
</main>

<footer>
  <md-toolbar class="md-hue-2 md-scroll-shrink">
    <div layout="row" layout-align="center center" flex>
      Powered by Webocity Technologies
    </div>
  </md-toolbar>
</footer>


1

有很多方法可以实现这一点。我最喜欢的方法之一是不需要任何fixedabsolute定位(虽然完全有效),而是将内容设置为100%。但是,这只适用于固定页脚高度。

<main flex layout="column">
  <div>
    <div ui-view="" ></div>
  </div>     
  <footer>
    <md-toolbar class="md-hue-2 md-scroll-shrink">
      <div layout="row" layout-align="center center" flex>
        Powered by Webocity Technologies
      </div>
    </md-toolbar>
  </footer>
</main>

并且你的CSS:

html, body {
  height: 100%;
  margin: 0;
}
[main] {
  min-height: 100%;
}
[footer] {
  height: 150px; // for this example, can be anything
  margin-top: -150px; // exact same value as the height
}

0

你可以在 footer.component.scss 中尝试使用这个 CSS 类:

.footer {
    bottom: 0;
    padding: 19px 15px 20px;
    position: absolute;
    right: 0;
    color:  #98a6ad;
    left: 210px;
    background-color: #ffffff;
    box-shadow: 0 0 1px rgba(50,58,70,.1);

    .footer-links {
        a {
            color:  #98a6ad;
            margin-left: 1.5rem;
            transition: all .4s;
            &:hover {
                color: #323a46;;
            }
            &:first-of-type {
                margin-left: 0;
            }
        }
    }
}

我认为最重要的是 bottom:0;position:absolute;,你可以尝试调整它们

同时别忘了在你的HTML中加入 <footer class="footer">

祝好,

朱利安


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接