美文网首页
【css】footer固定在页面底部

【css】footer固定在页面底部

作者: 豪秋 | 来源:发表于2018-08-14 21:59 被阅读0次

在chrome浏览器中,采用flexbox布局。

<!DOCTYPE html>
<html lang="en">

<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>Document</title>
  <style>
    html,
    body,
    div,
    header,
    section,
    footer {
      margin: 0;
      padding: 0;
    }

    #app {
      display: flex;
      flex-direction: column;
      width: 100%;
      min-height: 100vh;
      background-color: aquamarine;
      text-align: center;
    }

    header {
      height: 50px;
      background-color: greenyellow;
    }

    section {
      flex: 1 0 auto;
    }

    footer {
      height: 60px;
      background-color: #000;
      color: #fff;
    }
  </style>
</head>

<body>
  <div id="app">
    <header>this is a header</header>
    <section>this is a section.</section>
    <footer>this is a footer.</footer>
  </div>
</body>

</html>

在支持flex布局的chrome浏览器中打开,没有问题。但是在IE11中打开,缺没有想要的效果。
为了兼容IE11,在网上搜寻了个方法,代码如下:

<!DOCTYPE html>
<html lang="en">

<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>Document</title>
  <style>
    html,
    body,
    div,
    header,
    section,
    footer {
      margin: 0;
      padding: 0;
    }
    #app{
      display: flex;
    }

    #page {
      display: flex;
      flex-direction: column;
      width: 100%;
      min-height: 100vh;
      background-color: aquamarine;
      text-align: center;
    }

    header {
      height: 50px;
      background-color: greenyellow;
    }

    section {
      flex: 1 0 auto;
    }

    footer {
      height: 60px;
      background-color: #000;
      color: #fff;
    }
  </style>
</head>

<body>
  <div id="app">
    <div id="page">
      <header>this is a header</header>
      <section>this is a section.</section>
      <footer>this is a footer.</footer>
    </div>
  </div>
</body>

</html>

如此,对于IE11也有效果了。

相关文章

  • 【css】footer固定在页面底部

    在chrome浏览器中,采用flexbox布局。 在支持flex布局的chrome浏览器中打开,没有问题。但是在I...

  • 41 紧贴底部的页面

    解决将footer固定在页面底部的问题 在线预览 100vh占据100%可视窗口,利用calc计算,将底部的高度减...

  • 利用CSS进行布局和第一天的TODO

    如何让footer固定在底部? 多次在项目中遇到需要将footer固定在底部即使是中间内容并没有充满一屏的高度,如...

  • 使用css让Footer 保持在页面底部的方法

    使用css让Footer 保持在页面底部的方法 如题这次要讨论的是使用css方法,当然也可以通过js实现需求,虽然...

  • CSS Footer固定底部处理

    Footer应用场景 自适应内容高度展示在页面最底部 固定于浏览器窗口底部 Footer 自适应内容高度展示在页面...

  • css实现Sticky Footer

    所谓 “Sticky Footer”,指的就是一种网页效果: 如果页面内容不足够长时,页脚固定在浏览器窗口的底部;...

  • CSS方案总结

    一、Sticky Footer效果 无论页面内容高度如何变化,footer始终在页面底部的固定位置 二、垂直居中 ...

  • flex常用布局

    Sticky Footer 当页面内容高度小于可视区域高度时,footer 吸附在底部;当页面内容高度大于可视区域...

  • 页面常用代码整理

    在页面不够高的时候,footer永远保持在底部的css代码 导航栏的active的js代码 banner大图的自适...

  • Sticky footer 页面底部

    Sticky footer:页面内容不够长的时候,页脚块粘贴在视窗底部;如果内容足够长时,页脚块会被内容向下推送。...

网友评论

      本文标题:【css】footer固定在页面底部

      本文链接:https://www.haomeiwen.com/subject/wgebbftx.html